mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
C#: Replace Guards with the new implementation.
This commit is contained in:
@@ -10,7 +10,6 @@ module Stages {
|
||||
cached
|
||||
module ControlFlowStage {
|
||||
private import semmle.code.csharp.controlflow.internal.Splitting
|
||||
private import semmle.code.csharp.controlflow.Guards as Guards
|
||||
|
||||
cached
|
||||
predicate forceCachingInSameStage() { any() }
|
||||
@@ -21,8 +20,6 @@ module Stages {
|
||||
or
|
||||
exists(ControlFlow::Node n)
|
||||
or
|
||||
Guards::Internal::isCustomNullCheck(_, _, _, _)
|
||||
or
|
||||
forceCachingInSameStageRev()
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2906,7 +2906,8 @@ class DataFlowExpr = Expr;
|
||||
|
||||
/** Holds if `e` is an expression that always has the same Boolean value `val`. */
|
||||
private predicate constantBooleanExpr(Expr e, boolean val) {
|
||||
e = any(AbstractValues::BooleanValue bv | val = bv.getValue()).getAnExpr()
|
||||
e.getType() instanceof BoolType and
|
||||
e.getValue() = val.toString()
|
||||
or
|
||||
exists(Ssa::ExplicitDefinition def, Expr src |
|
||||
e = def.getARead() and
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,11 +2,5 @@ import csharp
|
||||
private import semmle.code.csharp.controlflow.Guards
|
||||
|
||||
query predicate abstractValue(AbstractValue value, Expr e) {
|
||||
e = value.getAnExpr() and e.fromSource()
|
||||
}
|
||||
|
||||
query predicate dualValue(AbstractValue value, AbstractValue dual) { dual = value.getDualValue() }
|
||||
|
||||
query predicate singletonValue(AbstractValue value) {
|
||||
value.isSingleton() and value.getAnExpr().fromSource()
|
||||
Guards::InternalUtil::exprHasValue(e, value) and e.fromSource()
|
||||
}
|
||||
|
||||
@@ -190,12 +190,12 @@
|
||||
| E.cs:83:13:83:24 | ... != ... | false | E.cs:83:21:83:24 | null | E.cs:83:13:83:16 | access to parameter vals |
|
||||
| E.cs:85:18:85:29 | ... != ... | false | E.cs:85:18:85:21 | access to parameter vals | E.cs:85:26:85:29 | null |
|
||||
| E.cs:85:18:85:29 | ... != ... | false | E.cs:85:26:85:29 | null | E.cs:85:18:85:21 | access to parameter vals |
|
||||
| E.cs:90:17:90:27 | access to local variable switchguard | match access to constant MY_CONST_A | E.cs:90:17:90:27 | access to local variable switchguard | E.cs:92:18:92:27 | access to constant MY_CONST_A |
|
||||
| E.cs:90:17:90:27 | access to local variable switchguard | match access to constant MY_CONST_A | E.cs:92:18:92:27 | access to constant MY_CONST_A | E.cs:90:17:90:27 | access to local variable switchguard |
|
||||
| E.cs:90:17:90:27 | access to local variable switchguard | match access to constant MY_CONST_B | E.cs:90:17:90:27 | access to local variable switchguard | E.cs:97:18:97:27 | access to constant MY_CONST_B |
|
||||
| E.cs:90:17:90:27 | access to local variable switchguard | match access to constant MY_CONST_B | E.cs:97:18:97:27 | access to constant MY_CONST_B | E.cs:90:17:90:27 | access to local variable switchguard |
|
||||
| E.cs:90:17:90:27 | access to local variable switchguard | match access to constant MY_CONST_C | E.cs:90:17:90:27 | access to local variable switchguard | E.cs:95:18:95:27 | access to constant MY_CONST_C |
|
||||
| E.cs:90:17:90:27 | access to local variable switchguard | match access to constant MY_CONST_C | E.cs:95:18:95:27 | access to constant MY_CONST_C | E.cs:90:17:90:27 | access to local variable switchguard |
|
||||
| E.cs:92:13:92:28 | case ...: | true | E.cs:90:17:90:27 | access to local variable switchguard | E.cs:92:18:92:27 | access to constant MY_CONST_A |
|
||||
| E.cs:92:13:92:28 | case ...: | true | E.cs:92:18:92:27 | access to constant MY_CONST_A | E.cs:90:17:90:27 | access to local variable switchguard |
|
||||
| E.cs:95:13:95:28 | case ...: | true | E.cs:90:17:90:27 | access to local variable switchguard | E.cs:95:18:95:27 | access to constant MY_CONST_C |
|
||||
| E.cs:95:13:95:28 | case ...: | true | E.cs:95:18:95:27 | access to constant MY_CONST_C | E.cs:90:17:90:27 | access to local variable switchguard |
|
||||
| E.cs:97:13:97:28 | case ...: | true | E.cs:90:17:90:27 | access to local variable switchguard | E.cs:97:18:97:27 | access to constant MY_CONST_B |
|
||||
| E.cs:97:13:97:28 | case ...: | true | E.cs:97:18:97:27 | access to constant MY_CONST_B | E.cs:90:17:90:27 | access to local variable switchguard |
|
||||
| E.cs:126:21:126:29 | ... == ... | true | E.cs:126:21:126:24 | access to local variable step | E.cs:126:29:126:29 | 0 |
|
||||
| E.cs:126:21:126:29 | ... == ... | true | E.cs:126:29:126:29 | 0 | E.cs:126:21:126:24 | access to local variable step |
|
||||
| E.cs:153:13:153:24 | ... != ... | false | E.cs:153:13:153:16 | access to local variable obj2 | E.cs:153:21:153:24 | null |
|
||||
@@ -252,6 +252,8 @@
|
||||
| E.cs:442:13:442:18 | ... == ... | true | E.cs:442:18:442:18 | 1 | E.cs:442:13:442:13 | access to parameter i |
|
||||
| E.cs:447:13:447:18 | ... == ... | true | E.cs:447:13:447:13 | access to parameter i | E.cs:447:18:447:18 | 2 |
|
||||
| E.cs:447:13:447:18 | ... == ... | true | E.cs:447:18:447:18 | 2 | E.cs:447:13:447:13 | access to parameter i |
|
||||
| E.cs:447:23:447:35 | ... is ... | false | E.cs:447:23:447:23 | access to parameter s | E.cs:447:32:447:35 | null |
|
||||
| E.cs:447:23:447:35 | ... is ... | false | E.cs:447:32:447:35 | null | E.cs:447:23:447:23 | access to parameter s |
|
||||
| E.cs:452:13:452:18 | ... == ... | true | E.cs:452:13:452:13 | access to parameter i | E.cs:452:18:452:18 | 3 |
|
||||
| E.cs:452:13:452:18 | ... == ... | true | E.cs:452:18:452:18 | 3 | E.cs:452:13:452:13 | access to parameter i |
|
||||
| Forwarding.cs:59:13:59:21 | ... == ... | true | Forwarding.cs:59:13:59:13 | access to parameter o | Forwarding.cs:59:18:59:21 | null |
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import csharp
|
||||
import semmle.code.csharp.controlflow.Guards
|
||||
|
||||
from Expr e1, AbstractValue v, Expr e2
|
||||
select Internal::getAnEqualityCheck(e1, v, e2), v, e1, e2
|
||||
from Guard guard, Expr e1, Expr e2, boolean eqval
|
||||
where guard.isEquality(e1, e2, eqval)
|
||||
select guard, eqval, e1, e2
|
||||
|
||||
@@ -28,7 +28,7 @@ class ForwardingTests
|
||||
|
||||
if (IsNotNull(s))
|
||||
{
|
||||
Console.WriteLine(s.Length); // GOOD
|
||||
Console.WriteLine(s.Length); // $ SPURIOUS (false positive): Alert[cs/dereferenced-value-is-always-null]
|
||||
}
|
||||
|
||||
if (IsNotNullWrong(s))
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
| E.cs:405:16:405:16 | access to local variable i | Variable $@ is always null at this dereference. | E.cs:403:14:403:14 | i | i |
|
||||
| E.cs:439:13:439:13 | access to parameter s | Variable $@ is always null at this dereference. | E.cs:435:29:435:29 | s | s |
|
||||
| F.cs:8:9:8:9 | access to local variable o | Variable $@ is always null at this dereference. | F.cs:7:16:7:16 | o | o |
|
||||
| Forwarding.cs:31:31:31:31 | access to local variable s | Variable $@ is always null at this dereference. | Forwarding.cs:7:16:7:16 | s | s |
|
||||
| Forwarding.cs:36:31:36:31 | access to local variable s | Variable $@ is always null at this dereference. | Forwarding.cs:7:16:7:16 | s | s |
|
||||
| Forwarding.cs:40:27:40:27 | access to local variable s | Variable $@ is always null at this dereference. | Forwarding.cs:7:16:7:16 | s | s |
|
||||
| NullAlwaysBad.cs:9:30:9:30 | access to parameter s | Variable $@ is always null at this dereference. | NullAlwaysBad.cs:7:29:7:29 | s | s |
|
||||
|
||||
Reference in New Issue
Block a user