C#: Fix false positives in cs/dereferenced-value-may-be-null

This commit is contained in:
Tom Hvitved
2018-12-11 10:00:42 +01:00
parent 287ce4e683
commit 078dc7b6c0
6 changed files with 14 additions and 5 deletions

View File

@@ -578,8 +578,12 @@ module Internal {
*/
Expr getNullEquivParent(Expr e) {
result = any(QualifiableExpr qe |
qe.getQualifier() = e and
qe.isConditional() and
(
e = qe.getQualifier()
or
e = qe.(ExtensionMethodCall).getArgument(0)
) and
(
// The accessed declaration must have a value type in order
// for `only if` to hold

View File

@@ -155,6 +155,9 @@ private predicate defMaybeNull(Ssa::Definition def, string msg, Element reason)
reason = de.getANullCheck(_, true) and
msg = "as suggested by $@ null check" and
not def instanceof Ssa::PseudoDefinition and
strictcount(Location l |
l = any(Ssa::Definition def0 | de = def0.getARead()).getLocation()
) = 1 and
not nonNullDef(def) and
// Don't use a check as reason if there is a `null` assignment
not def.(Ssa::ExplicitDefinition).getADefinition().getSource() instanceof MaybeNullExpr