mirror of
https://github.com/github/codeql.git
synced 2026-05-04 05:05:12 +02:00
C#: Fix some alerts, and fix a potential NullReferenceException.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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; }
|
||||
|
||||
Reference in New Issue
Block a user