CPP: Fix false positives in while/for loops.

This commit is contained in:
Geoffrey White 2018-11-08 18:13:28 +00:00
Родитель 136ca72297
Коммит 83d4b23ae3
3 изменённых файлов: 5 добавлений и 7 удалений

Просмотреть файл

@ -10,12 +10,12 @@
import cpp
Loop getAFalseLoop() {
DoStmt getAFalseLoop() {
result.getControllingExpr().getValue() = "0"
and not result.getControllingExpr().isAffectedByMacro()
}
Loop enclosingLoop(Stmt s) {
DoStmt enclosingLoop(Stmt s) {
exists(Stmt parent |
parent = s.getParent() and
if parent instanceof Loop then
@ -24,7 +24,7 @@ Loop enclosingLoop(Stmt s) {
result = enclosingLoop(parent))
}
from Loop loop, ContinueStmt continue
from DoStmt loop, ContinueStmt continue
where loop = getAFalseLoop()
and loop = enclosingLoop(continue)
select continue,

Просмотреть файл

@ -1,4 +1,2 @@
| 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 |
| 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 |
| 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 |
| 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 |

Просмотреть файл

@ -36,7 +36,7 @@ void test1()
while (false)
{
if (cond())
continue; // GOOD [never reached, if the condition changed so it was then the result would no longer apply] [FALSE POSITIVE]
continue; // GOOD [never reached, if the condition changed so it was then the result would no longer apply]
if (cond())
break;
}
@ -44,7 +44,7 @@ void test1()
for (i = 0; false; i++)
{
if (cond())
continue; // GOOD [never reached, if the condition changed so it was then the result would no longer apply] [FALSE POSITIVE]
continue; // GOOD [never reached, if the condition changed so it was then the result would no longer apply]
if (cond())
break;
}