mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
Merge pull request #1515 from geoffw0/continuefalseloop
CPP: Improvements to ContinueInFalseLoop.ql
This commit is contained in:
@@ -0,0 +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: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 |
|
||||
@@ -0,0 +1 @@
|
||||
Likely Bugs/ContinueInFalseLoop.ql
|
||||
@@ -0,0 +1,94 @@
|
||||
|
||||
bool cond();
|
||||
|
||||
void test1(int x)
|
||||
{
|
||||
int i;
|
||||
|
||||
// --- do loops ---
|
||||
|
||||
do
|
||||
{
|
||||
if (cond())
|
||||
continue; // BAD
|
||||
if (cond())
|
||||
break;
|
||||
} while (false);
|
||||
|
||||
do
|
||||
{
|
||||
if (cond())
|
||||
continue;
|
||||
if (cond())
|
||||
break;
|
||||
} while (true);
|
||||
|
||||
do
|
||||
{
|
||||
if (cond())
|
||||
continue;
|
||||
if (cond())
|
||||
break;
|
||||
} while (cond());
|
||||
|
||||
// --- while, for loops ---
|
||||
|
||||
while (false)
|
||||
{
|
||||
if (cond())
|
||||
continue; // GOOD [never reached, if the condition changed so it was then the result would no longer apply]
|
||||
if (cond())
|
||||
break;
|
||||
}
|
||||
|
||||
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]
|
||||
if (cond())
|
||||
break;
|
||||
}
|
||||
|
||||
// --- nested loops ---
|
||||
|
||||
do
|
||||
{
|
||||
do
|
||||
{
|
||||
if (cond())
|
||||
continue; // BAD
|
||||
if (cond())
|
||||
break;
|
||||
} while (false);
|
||||
} while (true);
|
||||
|
||||
do
|
||||
{
|
||||
do
|
||||
{
|
||||
if (cond())
|
||||
continue; // GOOD
|
||||
if (cond())
|
||||
break;
|
||||
} while (true);
|
||||
} while (false);
|
||||
|
||||
do
|
||||
{
|
||||
switch (x)
|
||||
{
|
||||
case 1:
|
||||
// do [1]
|
||||
|
||||
break; // break out of the switch
|
||||
|
||||
default:
|
||||
// do [2]
|
||||
|
||||
continue; // GOOD; break out of the loop entirely, skipping [3]
|
||||
};
|
||||
|
||||
// do [3]
|
||||
|
||||
} while (0);
|
||||
}
|
||||
Reference in New Issue
Block a user