Skip to content

Commit a7fb2e1

Browse files
committed
CPP: More test cases for ArithmeticWithExtremeValues.
1 parent f8655b1 commit a7fb2e1

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

cpp/ql/test/query-tests/Security/CWE/CWE-190/semmle/extreme/ArithmeticWithExtremeValues.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@
66
| test.c:63:3:63:5 | sc8 | $@ flows to here and is used in arithmetic, potentially causing an underflow. | test.c:62:9:62:16 | - ... | Extreme value |
77
| test.c:75:3:75:5 | sc1 | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.c:74:9:74:16 | 127 | Extreme value |
88
| test.c:76:3:76:5 | sc1 | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.c:74:9:74:16 | 127 | Extreme value |
9+
| test.c:114:9:114:9 | x | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.c:108:17:108:23 | 2147483647 | Extreme value |
10+
| test.c:124:9:124:9 | x | $@ flows to here and is used in arithmetic, potentially causing an overflow. | test.c:118:17:118:23 | 2147483647 | Extreme value |

cpp/ql/test/query-tests/Security/CWE/CWE-190/semmle/extreme/test.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,43 @@ void test_negatives() {
8383
sc5 = -1;
8484
sc5 += CHAR_MIN; // BAD [NOT DETECTED]
8585
}
86+
87+
void test_guards1(int cond) {
88+
int x = cond ? INT_MAX : 0;
89+
90+
// ...
91+
92+
if (x > 128) return;
93+
94+
return x + 1; // GOOD
95+
}
96+
97+
void test_guards2(int cond) {
98+
int x = cond ? INT_MAX : 0;
99+
100+
// ...
101+
102+
if (x < 128) return;
103+
104+
return x + 1; // BAD [NOT DETECTED]
105+
}
106+
107+
void test_guards3(int cond) {
108+
int x = cond ? INT_MAX : 0;
109+
110+
// ...
111+
112+
if (x != 0) return;
113+
114+
return x + 1; // GOOD [FALSE POSITIVE]
115+
}
116+
117+
void test_guards4(int cond) {
118+
int x = cond ? INT_MAX : 0;
119+
120+
// ...
121+
122+
if (x == 0) return;
123+
124+
return x + 1; // BAD
125+
}

0 commit comments

Comments
 (0)