Skip to content

Commit ed3ed5f

Browse files
committed
C++: Test to show lack of flow to crement operands
1 parent ceeb9ab commit ed3ed5f

3 files changed

Lines changed: 31 additions & 0 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
void test_crement() {
2+
int x1 = 0;
3+
++x1; // flow [NOT DETECTED]
4+
5+
int x2 = 0;
6+
x2++; // flow [NOT DETECTED]
7+
8+
int x3 = 0;
9+
x3 -= 1; // flow [NOT DETECTED]
10+
11+
int x4 = 0;
12+
x4 |= 1; // flow [NOT DETECTED]
13+
14+
int x5 = 0;
15+
x5 = x5 - 1; // flow (to RHS)
16+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| crements.cpp:15:8:15:9 | x5 |
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import cpp
2+
import semmle.code.cpp.ir.dataflow.DataFlow
3+
4+
class Cfg extends DataFlow::Configuration {
5+
Cfg() { this = "from0::Cfg" }
6+
7+
override predicate isSource(DataFlow::Node source) { source.asExpr().getValue() = "0" }
8+
9+
override predicate isSink(DataFlow::Node sink) { sink.asExpr() instanceof VariableAccess }
10+
}
11+
12+
from Cfg cfg, Expr sink
13+
where cfg.hasFlowToExpr(sink)
14+
select sink

0 commit comments

Comments
 (0)