Skip to content

Commit cbf30e3

Browse files
committed
C++: Fix the issue.
1 parent a7564c9 commit cbf30e3

File tree

3 files changed

+4
-11
lines changed

3 files changed

+4
-11
lines changed

cpp/ql/src/Likely Bugs/Likely Typos/inconsistentLoopDirection.ql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ predicate illDefinedDecrForStmt(
5454
or
5555
(forstmt.conditionAlwaysFalse() or forstmt.conditionAlwaysTrue())
5656
)
57-
)
57+
) and
58+
// exclude cases where the loop counter is `unsigned` (where wrapping behaviour can be used deliberately)
59+
not v.getUnspecifiedType().(IntegralType).isUnsigned()
5860
}
5961

6062
pragma[noinline]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void Unsigned()
2424
{
2525
unsigned long i;
2626

27-
for (i = 0; i < 100; i--) //BUG
27+
for (i = 0; i < 100; i--) //BUG [NOT DETECTED]
2828
{
2929
}
3030

Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
| inconsistentLoopDirection.c:5:5:7:5 | for(...;...;...) ... | Ill-defined for-loop: a loop using variable "i" counts downward from a value (0), but the terminal condition is higher (100). |
22
| inconsistentLoopDirection.c:13:5:15:5 | for(...;...;...) ... | Ill-defined for-loop: a loop using variable "i" counts upward from a value (100), but the terminal condition is lower (0). |
3-
| inconsistentLoopDirection.c:27:5:29:5 | for(...;...;...) ... | Ill-defined for-loop: a loop using variable "i" counts downward from a value (0), but the terminal condition is higher (100). |
43
| inconsistentLoopDirection.c:35:5:37:5 | for(...;...;...) ... | Ill-defined for-loop: a loop using variable "i" counts upward from a value (100), but the terminal condition is lower (0). |
54
| inconsistentLoopDirection.c:48:5:50:5 | for(...;...;...) ... | Ill-defined for-loop: a loop using variable "i" counts downward from a value (0), but the terminal condition is higher (100). |
65
| inconsistentLoopDirection.c:58:5:60:5 | for(...;...;...) ... | Ill-defined for-loop: a loop using variable "i" counts upward from a value (100), but the terminal condition is lower (0). |
76
| inconsistentLoopDirection.cpp:5:5:7:5 | for(...;...;...) ... | Ill-defined for-loop: a loop using variable "i" counts downward from a value (0), but the terminal condition is higher (100). |
87
| inconsistentLoopDirection.cpp:13:5:15:5 | for(...;...;...) ... | Ill-defined for-loop: a loop using variable "i" counts upward from a value (100), but the terminal condition is lower (0). |
9-
| inconsistentLoopDirection.cpp:27:5:29:5 | for(...;...;...) ... | Ill-defined for-loop: a loop using variable "i" counts downward from a value (0), but the terminal condition is higher (100). |
108
| inconsistentLoopDirection.cpp:35:5:37:5 | for(...;...;...) ... | Ill-defined for-loop: a loop using variable "i" counts upward from a value (100), but the terminal condition is lower (0). |
119
| inconsistentLoopDirection.cpp:46:5:48:5 | for(...;...;...) ... | Ill-defined for-loop: a loop using variable "i" counts downward from a value (0), but the terminal condition is higher (100). |
1210
| inconsistentLoopDirection.cpp:54:5:56:5 | for(...;...;...) ... | Ill-defined for-loop: a loop using variable "i" counts upward from a value (100), but the terminal condition is lower (0). |
@@ -16,14 +14,7 @@
1614
| inconsistentLoopDirection.cpp:101:5:103:5 | for(...;...;...) ... | Ill-defined for-loop: a loop using variable "i" counts upward from a value (100), but the terminal condition is lower (0). |
1715
| inconsistentLoopDirection.cpp:118:5:120:5 | for(...;...;...) ... | Ill-defined for-loop: a loop using variable "i" counts downward from a value (max), but the terminal condition is always false. |
1816
| inconsistentLoopDirection.cpp:122:5:124:5 | for(...;...;...) ... | Ill-defined for-loop: a loop using variable "i" counts upward from a value (min), but the terminal condition is always false. |
19-
| inconsistentLoopDirection.cpp:133:5:135:5 | for(...;...;...) ... | Ill-defined for-loop: a loop using variable "i" counts downward from a value (100), but the terminal condition is always false. |
2017
| inconsistentLoopDirection.cpp:140:5:142:5 | for(...;...;...) ... | Ill-defined for-loop: a loop using variable "i" counts upward from a value (200), but the terminal condition is lower (0). |
2118
| inconsistentLoopDirection.cpp:175:5:175:36 | for(...;...;...) ... | Ill-defined for-loop: a loop using variable "i" counts downward from a value (0), but the terminal condition is higher (10). |
2219
| 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). |
23-
| inconsistentLoopDirection.cpp:188:5:188:32 | for(...;...;...) ... | Ill-defined for-loop: a loop using variable "i" counts downward from a value (63), but the terminal condition is higher (64). |
24-
| inconsistentLoopDirection.cpp:189:5:189:33 | for(...;...;...) ... | Ill-defined for-loop: a loop using variable "i" counts downward from a value (63), but the terminal condition is higher (128). |
25-
| inconsistentLoopDirection.cpp:190:5:190:33 | for(...;...;...) ... | Ill-defined for-loop: a loop using variable "i" counts downward from a value (63), but the terminal condition is higher (255). |
26-
| inconsistentLoopDirection.cpp:192:5:192:34 | for(...;...;...) ... | Ill-defined for-loop: a loop using variable "i" counts downward from a value (... - ...), but the terminal condition is higher (m). |
27-
| inconsistentLoopDirection.cpp:193:5:193:34 | for(...;...;...) ... | Ill-defined for-loop: a loop using variable "i" counts downward from a value (... - ...), but the terminal condition is higher (m). |
28-
| inconsistentLoopDirection.cpp:194:5:194:34 | for(...;...;...) ... | Ill-defined for-loop: a loop using variable "i" counts downward from a value (... - ...), but the terminal condition is higher (m). |
2920
| 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). |

0 commit comments

Comments
 (0)