mirror of
https://github.com/github/codeql.git
synced 2026-05-05 05:35:13 +02:00
C#: Exclude interfaces and abstract classes from cs/call-to-object-tostring
This commit is contained in:
@@ -54,7 +54,9 @@ predicate alwaysDefaultToString(ValueOrRefType t) {
|
||||
not exists(RefType overriding |
|
||||
overriding.getAMethod() instanceof ToStringMethod and
|
||||
overriding.getABaseType+() = t
|
||||
)
|
||||
) and
|
||||
not t.isAbstract() and
|
||||
not t instanceof Interface
|
||||
}
|
||||
|
||||
newtype TDefaultToStringType = TDefaultToStringType0(ValueOrRefType t) { alwaysDefaultToString(t) }
|
||||
|
||||
@@ -29,6 +29,9 @@ class DefaultToString
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.Append(new char[] { 'a', 'b', 'c' }, 0, 3); // GOOD
|
||||
|
||||
IInterface f = null;
|
||||
Console.WriteLine(f); // GOOD
|
||||
}
|
||||
|
||||
class A
|
||||
@@ -48,6 +51,10 @@ class DefaultToString
|
||||
{
|
||||
override public string ToString() { return "D"; }
|
||||
}
|
||||
|
||||
interface IInterface
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// semmle-extractor-options: /r:System.Runtime.Extensions.dll
|
||||
|
||||
Reference in New Issue
Block a user