C#: Fix some alerts, and fix a potential NullReferenceException.

This commit is contained in:
calum
2019-01-11 12:12:11 +00:00
parent b0dd3dfeb1
commit fb0cae87a8
5 changed files with 9 additions and 3 deletions

View File

@@ -402,6 +402,9 @@ namespace Semmle.Extraction.CIL.Entities
declType = parentMethod == null ? parent as Type : parentMethod.DeclaringType;
if (declType is null)
throw new InternalError("Parent context of method is not a type");
ShortId = MakeMethodId(declType, nameLabel);
var typeSourceDeclaration = declType.SourceDeclaration;

View File

@@ -1121,7 +1121,7 @@ namespace Semmle.Extraction.CIL.Entities
static readonly Id excl = Id.Create("M!");
public Id MakeId(GenericContext outerGc)
{
if (innerGc != outerGc && innerGc is Method method)
if (!ReferenceEquals(innerGc, outerGc) && innerGc is Method method)
return open + method.Label.Value + close + excl + index;
return excl + index;
}

View File

@@ -134,6 +134,9 @@ namespace Semmle.Extraction.CSharp.Entities
if (symbol.Kind == SymbolKind.NamedType)
{
INamedTypeSymbol nt = symbol as INamedTypeSymbol;
if (nt is null)
throw new InternalError(symbol, "Symbol kind is inconsistent with its type");
if (nt.TypeKind == TypeKind.Struct)
{
// Sadly, these properties are internal so cannot be accessed directly.

View File

@@ -93,7 +93,7 @@ namespace Semmle.Extraction
{
if (idLabelCache.TryGetValue(id, out var originalEntity))
{
Extractor.Message(new Message { message = "Label collision for " + id.ToString(), severity = Severity.Warning });
Extractor.Message(new Message { message = "Label collision for " + id, severity = Severity.Warning });
}
else
{

View File

@@ -57,7 +57,7 @@ namespace Semmle.Extraction
public override bool Equals(object obj)
{
var other = obj as CachedEntity<Initializer>;
return obj != null && obj.GetType() == GetType() && Equals(other.symbol, symbol);
return other != null && other.GetType() == GetType() && Equals(other.symbol, symbol);
}
public abstract TrapStackBehaviour TrapStackBehaviour { get; }