зеркало из https://github.com/github/codeql.git
CPP: Fix false positives in while/for loops.
This commit is contained in:
Родитель
136ca72297
Коммит
83d4b23ae3
|
@ -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;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче