Skip to content

Commit 517fd23

Browse files
committed
C++: Correct and add to test cases.
1 parent a8193da commit 517fd23

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

cpp/ql/test/query-tests/Security/CWE/CWE-191/UnsignedDifferenceExpressionComparedZero/UnsignedDifferenceExpressionComparedZero.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@
1818
| test.cpp:208:6:208:14 | ... > ... | Unsigned subtraction can never be negative. |
1919
| test.cpp:252:10:252:18 | ... > ... | Unsigned subtraction can never be negative. |
2020
| test.cpp:266:10:266:24 | ... > ... | Unsigned subtraction can never be negative. |
21+
| test.cpp:276:11:276:19 | ... > ... | Unsigned subtraction can never be negative. |
22+
| test.cpp:288:10:288:18 | ... > ... | Unsigned subtraction can never be negative. |

cpp/ql/test/query-tests/Security/CWE/CWE-191/UnsignedDifferenceExpressionComparedZero/test.cpp

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ int test13() {
236236

237237
if (b != 0) {
238238
return 0;
239-
}
239+
} // b = 0
240240

241241
return (a - b > 0); // GOOD (as b = 0)
242242
}
@@ -247,9 +247,9 @@ int test14() {
247247

248248
if (!b) {
249249
return 0;
250-
}
250+
} // b != 0
251251

252-
return (a - b > 0); // GOOD (as b = 0) [FALSE POSITIVE]
252+
return (a - b > 0); // BAD
253253
}
254254

255255
struct Numbers
@@ -265,3 +265,36 @@ int test15(Numbers *n) {
265265

266266
return (n->a - n->b > 0); // BAD
267267
}
268+
269+
int test16() {
270+
unsigned int a = getAnInt();
271+
unsigned int b = getAnInt();
272+
273+
if (!b) {
274+
return 0;
275+
} else {
276+
return (a - b > 0); // BAD
277+
}
278+
}
279+
280+
int test17() {
281+
unsigned int a = getAnInt();
282+
unsigned int b = getAnInt();
283+
284+
if (b == 0) {
285+
return 0;
286+
} // b != 0
287+
288+
return (a - b > 0); // BAD
289+
}
290+
291+
int test18() {
292+
unsigned int a = getAnInt();
293+
unsigned int b = getAnInt();
294+
295+
if (b) {
296+
return 0;
297+
} // b == 0
298+
299+
return (a - b > 0); // GOOD (as b = 0)
300+
}

0 commit comments

Comments
 (0)