Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 83d4b23

Browse files
committed
CPP: Fix false positives in while/for loops.
1 parent 136ca72 commit 83d4b23

3 files changed

Lines changed: 5 additions & 7 deletions

File tree

cpp/ql/src/Likely Bugs/ContinueInFalseLoop.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010

1111
import cpp
1212

13-
Loop getAFalseLoop() {
13+
DoStmt getAFalseLoop() {
1414
result.getControllingExpr().getValue() = "0"
1515
and not result.getControllingExpr().isAffectedByMacro()
1616
}
1717

18-
Loop enclosingLoop(Stmt s) {
18+
DoStmt enclosingLoop(Stmt s) {
1919
exists(Stmt parent |
2020
parent = s.getParent() and
2121
if parent instanceof Loop then
@@ -24,7 +24,7 @@ Loop enclosingLoop(Stmt s) {
2424
result = enclosingLoop(parent))
2525
}
2626

27-
from Loop loop, ContinueStmt continue
27+
from DoStmt loop, ContinueStmt continue
2828
where loop = getAFalseLoop()
2929
and loop = enclosingLoop(continue)
3030
select continue,
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
| test.cpp:13:4:13:12 | continue; | This 'continue' never re-runs the loop - the $@ is always false. | test.cpp:16:11:16:15 | 0 | loop condition |
2-
| test.cpp:39:4:39:12 | continue; | This 'continue' never re-runs the loop - the $@ is always false. | test.cpp:36:9:36:13 | 0 | loop condition |
3-
| test.cpp:47:4:47:12 | continue; | This 'continue' never re-runs the loop - the $@ is always false. | test.cpp:44:14:44:18 | 0 | loop condition |
42
| test.cpp:59:5:59:13 | continue; | This 'continue' never re-runs the loop - the $@ is always false. | test.cpp:62:12:62:16 | 0 | loop condition |

cpp/ql/test/query-tests/Likely Bugs/ContinueInFalseLoop/test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ void test1()
3636
while (false)
3737
{
3838
if (cond())
39-
continue; // GOOD [never reached, if the condition changed so it was then the result would no longer apply] [FALSE POSITIVE]
39+
continue; // GOOD [never reached, if the condition changed so it was then the result would no longer apply]
4040
if (cond())
4141
break;
4242
}
4343

4444
for (i = 0; false; i++)
4545
{
4646
if (cond())
47-
continue; // GOOD [never reached, if the condition changed so it was then the result would no longer apply] [FALSE POSITIVE]
47+
continue; // GOOD [never reached, if the condition changed so it was then the result would no longer apply]
4848
if (cond())
4949
break;
5050
}

0 commit comments

Comments
 (0)