mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
Merge pull request #2175 from aschackmull/java/continue-in-false-loop
Java: Port C++ query cpp/continue-in-false-loop to Java.
This commit is contained in:
84
java/ql/test/query-tests/ContinueInFalseLoop/A.java
Normal file
84
java/ql/test/query-tests/ContinueInFalseLoop/A.java
Normal file
@@ -0,0 +1,84 @@
|
||||
public class A {
|
||||
|
||||
public interface Cond {
|
||||
boolean cond();
|
||||
}
|
||||
|
||||
void test1(int x, Cond c) {
|
||||
int i;
|
||||
|
||||
// --- do loops ---
|
||||
|
||||
do {
|
||||
if (c.cond())
|
||||
continue; // BAD
|
||||
if (c.cond())
|
||||
break;
|
||||
} while (false);
|
||||
|
||||
do {
|
||||
if (c.cond())
|
||||
continue;
|
||||
if (c.cond())
|
||||
break;
|
||||
} while (true);
|
||||
|
||||
do {
|
||||
if (c.cond())
|
||||
continue;
|
||||
if (c.cond())
|
||||
break;
|
||||
} while (c.cond());
|
||||
|
||||
// --- while, for loops ---
|
||||
|
||||
while (false) {
|
||||
if (c.cond())
|
||||
continue; // GOOD [never reached, if the condition changed so it was then the result would no longer apply]
|
||||
if (c.cond())
|
||||
break;
|
||||
}
|
||||
|
||||
for (i = 0; false; i++) {
|
||||
if (c.cond())
|
||||
continue; // GOOD [never reached, if the condition changed so it was then the result would no longer apply]
|
||||
if (c.cond())
|
||||
break;
|
||||
}
|
||||
|
||||
// --- nested loops ---
|
||||
|
||||
do {
|
||||
do {
|
||||
if (c.cond())
|
||||
continue; // BAD
|
||||
if (c.cond())
|
||||
break;
|
||||
} while (false);
|
||||
if (c.cond())
|
||||
break;
|
||||
} while (true);
|
||||
|
||||
do {
|
||||
do {
|
||||
if (c.cond())
|
||||
continue; // GOOD
|
||||
if (c.cond())
|
||||
break;
|
||||
} while (true);
|
||||
} while (false);
|
||||
|
||||
do {
|
||||
switch (x) {
|
||||
case 1:
|
||||
// do [1]
|
||||
break; // break out of the switch
|
||||
default:
|
||||
// do [2]
|
||||
// break out of the loop entirely, skipping [3]
|
||||
continue; // BAD; labelled break is better
|
||||
};
|
||||
// do [3]
|
||||
} while (false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
| A.java:14:9:14:17 | stmt | This 'continue' never re-runs the loop - the $@ is always false. | A.java:17:14:17:18 | false | loop condition |
|
||||
| A.java:54:11:54:19 | stmt | This 'continue' never re-runs the loop - the $@ is always false. | A.java:57:16:57:20 | false | loop condition |
|
||||
| A.java:79:9:79:17 | stmt | This 'continue' never re-runs the loop - the $@ is always false. | A.java:82:14:82:18 | false | loop condition |
|
||||
@@ -0,0 +1 @@
|
||||
Likely Bugs/Statements/ContinueInFalseLoop.ql
|
||||
Reference in New Issue
Block a user