We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7abece4 commit 1343e4cCopy full SHA for 1343e4c
cpp/ql/src/Security/CWE/CWE-191/UnsignedDifferenceExpressionComparedZero.c
@@ -1,10 +1,14 @@
1
-unsigned limit = get_limit();
2
-unsigned total = 0;
+uint32_t limit = get_limit();
+uint32_t total = 0;
3
4
while (limit - total > 0) { // BAD: if `total` is greater than `limit` this will underflow and continue executing the loop.
5
total += get_data();
6
}
7
8
-while (total < limit) { // GOOD: never underflows.
+while (total < limit) { // GOOD: never underflows here because there is no arithmetic.
9
+ total += get_data();
10
+}
11
+
12
+while ((int64_t)limit - total > 0) { // GOOD: never underflows here because the result always fits in an `int64_t`.
13
14
0 commit comments