Skip to content

Commit 3cf11ec

Browse files
committed
C++: And more test cases.
1 parent 7d491af commit 3cf11ec

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

cpp/ql/test/query-tests/Likely Bugs/Likely Typos/inconsistentLoopDirection/inconsistentLoopDirection.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,22 @@ void IntendedOverflow(unsigned char p)
198198

199199
for (i = p - 1; i < p; i--) {} // GOOD
200200
for (s = p - 1; s < p; s--) {} // BAD [NOT DETECTED]
201-
}
201+
202+
{
203+
int n;
204+
205+
n = 64;
206+
for (i = n - 1; i < n; i--) {} // GOOD
207+
n = 64;
208+
for (i = n - 1; i < 64; i--) {} // GOOD
209+
n = 64;
210+
for (i = 63; i < n; i--) {} // GOOD
211+
212+
n = 64;
213+
for (s = n - 1; s < n; s--) {} // BAD [NOT DETECTED]
214+
n = 64;
215+
for (s = n - 1; s < 64; s--) {} // BAD
216+
n = 64;
217+
for (s = 63; s < n; s--) {} // BAD [NOT DETECTED]
218+
}
219+
}

cpp/ql/test/query-tests/Likely Bugs/Likely Typos/inconsistentLoopDirection/inconsistentLoopDirection.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@
2222
| inconsistentLoopDirection.cpp:179:5:179:38 | for(...;...;...) ... | Ill-defined for-loop: a loop using variable "i" counts upward from a value (100), but the terminal condition is lower (0). |
2323
| inconsistentLoopDirection.cpp:196:5:196:32 | for(...;...;...) ... | Ill-defined for-loop: a loop using variable "s" counts downward from a value (63), but the terminal condition is higher (64). |
2424
| inconsistentLoopDirection.cpp:197:5:197:34 | for(...;...;...) ... | Ill-defined for-loop: a loop using variable "s" counts downward from a value (... + ...), but the terminal condition is always false. |
25+
| inconsistentLoopDirection.cpp:215:3:215:33 | for(...;...;...) ... | Ill-defined for-loop: a loop using variable "s" counts downward from a value (... - ...), but the terminal condition is higher (64). |

0 commit comments

Comments
 (0)