mirror of
https://github.com/github/codeql.git
synced 2026-04-24 16:25:15 +02:00
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:
@@ -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
|
||||
)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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. |
|
||||
|
||||
Reference in New Issue
Block a user