mirror of
https://github.com/github/codeql.git
synced 2026-05-02 20:25:13 +02:00
C++: accept loops with arbitrary labels or cases
This commit is contained in:
@@ -27,6 +27,7 @@ where b.getStmt(i) = js
|
||||
and not s instanceof SwitchCase
|
||||
// the next statement isn't breaking out of a switch
|
||||
and not s.(BreakStmt).getBreakable() instanceof SwitchStmt
|
||||
// the jump isn't a goto into the body of the next statement
|
||||
and not exists (LabelStmt ls | s.(Loop).getStmt().getAChild*() = ls | ls.getName() = js.(GotoStmt).getName())
|
||||
// the next statement isn't a loop that can be jumped into
|
||||
and not exists (LabelStmt ls | s.(Loop).getStmt().getAChild*() = ls)
|
||||
and not exists (SwitchCase sc | s.(Loop).getStmt().getAChild*() = sc)
|
||||
select js, "This statement makes $@ unreachable.", s, s.toString()
|
||||
|
||||
@@ -50,3 +50,34 @@ int test5(int x, int y) {
|
||||
return x;
|
||||
}
|
||||
|
||||
void test6(int x, int cond) {
|
||||
if (cond) {
|
||||
x++;
|
||||
} else goto end; // GOOD
|
||||
x++;
|
||||
end:
|
||||
}
|
||||
|
||||
void test7(int x, int cond) {
|
||||
if (cond)
|
||||
{
|
||||
goto target;
|
||||
}
|
||||
goto somewhere_else; // GOOD
|
||||
while (x < 10) // not dead code
|
||||
{
|
||||
target:
|
||||
x++;
|
||||
}
|
||||
somewhere_else:
|
||||
switch (1)
|
||||
{
|
||||
goto end;
|
||||
while (x < 10) // not dead code
|
||||
{
|
||||
case 1:
|
||||
x++;
|
||||
} break;
|
||||
}
|
||||
end:
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user