mirror of
https://github.com/github/codeql.git
synced 2026-04-21 15:05:56 +02:00
C++: Add a 'good' example for cpp/unsigned-difference-expression-compared-zero.
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
unsigned limit = get_limit();
|
||||
unsigned total = 0;
|
||||
while (limit - total > 0) { // wrong: if `total` is greater than `limit` this will underflow and continue executing the loop.
|
||||
|
||||
while (limit - total > 0) { // BAD: if `total` is greater than `limit` this will underflow and continue executing the loop.
|
||||
total += get_data();
|
||||
}
|
||||
}
|
||||
|
||||
while (total < limit) { // GOOD: never underflows.
|
||||
total += get_data();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user