C#: Fix FP in expressions of the form (a?b:null)??d, where the null has a single successor, but the d is a join node.

This commit is contained in:
calum
2019-04-01 15:23:40 +01:00
parent 3e563f7a11
commit b11dce7b8a
3 changed files with 5 additions and 4 deletions

View File

@@ -71,8 +71,10 @@ class ConstantNullnessCondition extends ConstantCondition {
ConstantNullnessCondition() {
forex(ControlFlow::Node cfn | cfn = this.getAControlFlowNode() |
exists(ControlFlow::SuccessorTypes::NullnessSuccessor t | exists(cfn.getASuccessorByType(t)) |
b = t.getValue()
exists(ControlFlow::SuccessorTypes::NullnessSuccessor t, ControlFlow::Node s |
s = cfn.getASuccessorByType(t) |
b = t.getValue() and
not s.isJoin()
) and
strictcount(ControlFlow::SuccessorType t | exists(cfn.getASuccessorByType(t))) = 1
)

View File

@@ -50,7 +50,7 @@ class ConstantNullness
j = (int?)i ?? 1; // BAD
s = ""?.CommaJoinWith(s); // BAD
s = s ?? ""; // GOOD
s = (i==0 ? s : null) ?? s; // BAD (False positive)
s = (i==0 ? s : null) ?? s;
}
}

View File

@@ -4,7 +4,6 @@
| ConstantCondition.cs:49:17:49:18 | "" | Expression is never 'null'. |
| ConstantCondition.cs:50:13:50:19 | (...) ... | Expression is never 'null'. |
| ConstantCondition.cs:51:13:51:14 | "" | Expression is never 'null'. |
| ConstantCondition.cs:53:25:53:28 | null | Expression is always 'null'. |
| ConstantCondition.cs:63:18:63:18 | 2 | Pattern never matches. |
| ConstantCondition.cs:65:18:65:18 | 3 | Pattern always matches. |
| ConstantCondition.cs:76:18:76:20 | access to type Int32 | Pattern never matches. |