PVS-Studio checks Umbraco code for the third time

Introduction

How are the warnings doing?

protected virtual string VisitMethodCall(MethodCallExpression m)
{
....
case "SqlText":
if (m.Method.DeclaringType != typeof(SqlExtensionsStatics))
goto default;
if (m.Arguments.Count == 2)
{
var n1 = Visit(m.Arguments[0]);
var f = m.Arguments[2];
if (!(f is Expression<Func<string, string>> fl))
throw new NotSupportedException("Expression is not a proper
lambda.");
var ff = fl.Compile();
return ff(n1);
}
else if (m.Arguments.Count == 3)
{
var n1 = Visit(m.Arguments[0]);
var n2 = Visit(m.Arguments[1]);
var f = m.Arguments[2];
if (!(f is Expression<Func<string, string, string>> fl))
throw new NotSupportedException("Expression is not a proper
lambda.");
var ff = fl.Compile();
return ff(n1, n2);
}
else if (m.Arguments.Count == 4)
{
var n1 = Visit(m.Arguments[0]);
var n2 = Visit(m.Arguments[1]);
var n3 = Visit(m.Arguments[3]);
var f = m.Arguments[3];
if (!(f is Expression<Func<string, string, string, string>> fl))
throw new NotSupportedException("Expression is not a proper
lambda.");
var ff = fl.Compile();
return ff(n1, n2, n3);
}
else
throw new NotSupportedException("Expression is not a proper lambda.");
....
}
protected virtual string VisitMethodCall(MethodCallExpression m)
{
....
case "SqlText":
....
if (m.Arguments.Count == 2)
{
var n1 = Visit(m.Arguments[0]);
var f = m.Arguments[2];
....
}
}
public static string ToXmlString(this object value, Type type)
{
if (value == null) return string.Empty;
if (type == typeof(string))
return (value.ToString().IsNullOrWhiteSpace() ? "" : value.ToString());
if (type == typeof(bool)) return XmlConvert.ToString((bool)value);
if (type == typeof(byte)) return XmlConvert.ToString((byte)value);
if (type == typeof(char)) return XmlConvert.ToString((char)value);
if (type == typeof(DateTime)) return XmlConvert.ToString((DateTime)value,
XmlDateTimeSerializationMode.Unspecified);
if (type == typeof(DateTimeOffset))
return XmlConvert.ToString((DateTimeOffset)value);
if (type == typeof(decimal)) return XmlConvert.ToString((decimal)value);
if (type == typeof(double)) return XmlConvert.ToString((double)value);
if (type == typeof(float)) return XmlConvert.ToString((float)value);
if (type == typeof(Guid)) return XmlConvert.ToString((Guid)value);
if (type == typeof(int)) return XmlConvert.ToString((int)value);
if (type == typeof(long)) return XmlConvert.ToString((long)value);
if (type == typeof(sbyte)) return XmlConvert.ToString((sbyte)value);
if (type == typeof(short)) return XmlConvert.ToString((short)value);
if (type == typeof(TimeSpan)) return XmlConvert.ToString((TimeSpan)value);
if (type == typeof(bool)) return XmlConvert.ToString((bool)value);
if (type == typeof(uint)) return XmlConvert.ToString((uint)value);
if (type == typeof(ulong)) return XmlConvert.ToString((ulong)value);
if (type == typeof(ushort)) return XmlConvert.ToString((ushort)value);
....
}
public static string ToXmlString(this object value, Type type)
{
....
if (type == typeof(bool)) return XmlConvert.ToString((bool)value);
....
if (type == typeof(bool)) return XmlConvert.ToString((bool)value);
....
}
public bool FlagOutOfDateModels
{
get => _flagOutOfDateModels;
set
{
if (!ModelsMode.IsAuto())
{
_flagOutOfDateModels = false;
}
_flagOutOfDateModels = value;
}
}
private bool MatchesEndpoint(string absPath)
{
IEnumerable<RouteEndpoint> routeEndpoints = _endpointDataSource
?.Endpoints
.OfType<RouteEndpoint>()
.Where(x =>
{
....
});
var routeValues = new RouteValueDictionary(); RouteEndpoint matchedEndpoint = routeEndpoints
.Where(e => new TemplateMatcher(
TemplateParser.Parse(e.RoutePattern.RawText),
new RouteValueDictionary())
.TryMatch(absPath, routeValues))
.OrderBy(c => c.Order)
.FirstOrDefault();
return matchedEndpoint != null;
}
public void Handle(ContentCopiedNotification notification)
{
....
if (relationType == null)
{
relationType = new RelationType(
Constants.Conventions.RelationTypes.RelateDocumentOnCopyAlias,
Constants.Conventions.RelationTypes.RelateDocumentOnCopyName,
true,
Constants.ObjectTypes.Document,
Constants.ObjectTypes.Document);
_relationService.Save(relationType);
}
....
}
public RelationType(string name,
string alias,
bool isBidrectional,
Guid? parentObjectType,
Guid? childObjectType)
private static async Task<Attempt<UrlInfo>> DetectCollisionAsync(....)
{
....
if (pcr.IgnorePublishedContentCollisions)
{
logger.LogDebug(logMsg, url, uri, culture);
}
else
{
logger.LogDebug(logMsg, url, uri, culture);
}
}
public async Task<bool> IsMemberAuthorizedAsync(....)
{
....
if (IsLoggedIn() == false)
{
allowAction = false;
}
else
{
string username;
....
username = currentMember.UserName;
IList<string> allowTypesList = allowTypes as IList<string> ??
allowTypes.ToList();
if (allowTypesList.Any(allowType => allowType != string.Empty))
{
allowAction = allowTypesList.Select(x => x.ToLowerInvariant())
.Contains(currentMember
.MemberTypeAlias
.ToLowerInvariant());
}
if (allowAction && allowMembers.Any())
{
allowAction = allowMembers.Contains(memberId);
}
....
}
return allowAction;
}
public async Task<ActionResult<UserDisplay>> PostInviteUser(UserInvite userSave)
{
if (_securitySettings.UsernameIsEmail)
{
userSave.Username = userSave.Email;
}
else
{
var userResult = CheckUniqueUsername(userSave.Username, u =>
u.LastLoginDate != default
|| u.EmailConfirmedDate.HasValue);

if (!(userResult.Result is null))
{
return userResult.Result;
}
user = userResult.Value;
}
user = CheckUniqueEmail(userSave.Email, u => u.LastLoginDate != default ||
u.EmailConfirmedDate.HasValue);
....
}
public ActionResult<PagedResult<EntityBasic>> GetPagedChildren(....
int pageNumber,
....)
{
if (pageNumber <= 0)
{
return NotFound();
}
....
if (objectType.HasValue)
{
if (id == Constants.System.Root &&
startNodes.Length > 0 &&
startNodes.Contains(Constants.System.Root) == false &&
!ignoreUserStartNodes)
{
if (pageNumber > 0) // <=
{
return new PagedResult<EntityBasic>(0, 0, 0);
}
IEntitySlim[] nodes = _entityService.GetAll(objectType.Value,
startNodes).ToArray();
if (nodes.Length == 0)
{
return new PagedResult<EntityBasic>(0, 0, 0);
}
if (pageSize < nodes.Length)
{
pageSize = nodes.Length; // bah
}
var pr = new PagedResult<EntityBasic>(nodes.Length, pageNumber, pageSize)
{
Items = nodes.Select(_umbracoMapper.Map<EntityBasic>)
};
return pr;
}
}
}
Public void SimpleConverter3Test()
{
....
IpublishedContentType contentType1 =
contentTypeFactory.CreateContentType(Guid.NewGuid(),
1002, "content1", t => CreatePropertyTypes(t, 1));
IpublishedContentType contentType2 =
contentTypeFactory.CreateContentType(Guid.NewGuid(),
1003, "content2", t => CreatePropertyTypes(t, 2));
....
var cnt1 = new InternalPublishedContent(contentType1) // <=
{
Id = 1003,
Properties = new[]
{
new InternalPublishedProperty {Alias = "prop1",
SolidHasValue = true, SolidValue = "val1"}
}
};
var cnt2 = new InternalPublishedContent(contentType1) // <=
{
Id = 1004,
Properties = new[]
{
new InternalPublishedProperty {Alias = "prop2",
SolidHasValue = true, SolidValue = "1003"}
}
};
}

Conclusion

--

--

--

The developer, the debugger, the unicorn. I know all about static analysis and how to find bugs and errors in C, C++, C#, and Java source code.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Dependency Injection with Dagger

Creating Splash Screen in SwiftUI

“If it turns out that this is incurable, would you marry me?”

Setting up The Skeleton Attack System in Unity

Thoughts on Releasing Something into the World

List All Tables Stored in a SQL Server Backup (.BAK) File in Python

Seven Types of JAVA Garbage Collectors

SketchUp Axes Tips

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Unicorn Developer

Unicorn Developer

The developer, the debugger, the unicorn. I know all about static analysis and how to find bugs and errors in C, C++, C#, and Java source code.

More from Medium

Improve Code Readability With the Fluent Builder Pattern in C#

Improving Factory Pattern using DI in .Net

Write a URL Shortener in 26 Lines of Code with .NET Minimal APIs

In-Memory Repositories: A Forgotten Design Tool