False Negative: ContinueInFalseLoop.ql misses `do ... while(false)` loops once `false` is stored in a local.
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 68/100
Rechercherichtung
Beginne mit Likely Bugs/Statements/ContinueInFalseLoop.ql und prüfe, wie es do-Schleifenbedingungen auswertet, wenn false in einer lokalen Variable gespeichert ist. Überprüfe anschließend die betroffenen Fälle PosCase1_Var1.java und PosCase1_Var5.java und führe die Checker-Tests aus, um zu bestätigen, dass beide Fälle gemeldet werden, während das bestehende Verhalten für das Literal false weiterhin abgedeckt ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
False Negative: ContinueInFalseLoop.ql misses do ... while(false) loops once false is stored in a local.
Version
codeql 2.24.3
Checker
- Checker id:
Likely Bugs/Statements/ContinueInFalseLoop.ql - Checker description: This checker detects a 'continue' statement inside a 'do' loop whose condition is always false, meaning the continue will never actually re-run the loop body.
Description of the false negative
Both samples are still do loops whose condition is false and therefore cannot loop back after continue. The only difference is that the literal false is first assigned to a local variable.
That should still be a direct hit for Likely Bugs/Statements/ContinueInFalseLoop.ql.
Affected test cases
PosCase1_Var1.java
never is a constant false value, so the continue still cannot re-enter the loop body.
// A do loop with a literal false condition contains a continue statement targeting that same loop should be flagged as a positive case.
package scensct.var.pos;
public class PosCase1_Var1 {
public static void main(String[] args) {
final boolean never = false;
do {
// continue inside do with false condition
continue;
} while (never);
}
}
PosCase1_Var5.java
flag is initialized from Boolean.FALSE and never changed. This is still the same impossible loop-back case.
// A do loop with a literal false condition contains a continue statement targeting that same loop should be flagged as a positive case.
package scensct.var.pos;
public class PosCase1_Var5 {
public static void main(String[] args) {
boolean flag = Boolean.FALSE;
do {
// continue inside do with false condition
continue;
} while (flag);
}
}
Cause analysis
The miss is surprisingly basic. The query appears to require a literal false at the loop condition and loses the result as soon as that same value is stored in a local.
For developers, these are the same bug. Whether the condition is written as while (false) or while (never) should not matter.
References
None known.
- Vorherrschende Sprache
- CodeQL
- Sterne
- 10.1k
- Forks
- 2.1k
- Ø Merge
- 2 T. 16 Std.
- Gemergte PRs (30 T.)
- 143
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus github/codeql
-
agentic-workflows
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
-
false-positive javascript
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
-
C#: cs/simplifiable-boolean-expression false positive on Nullable<bool> compared with a literal Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
false-positive
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
palladius/rails8-app-on-gcp#145 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
elastic/gradle-plugins#156 ·
-
area:workflow bug ready-for-agent
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
fil-donadoni/tolaria#4409 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
dotenvx/dotenv-vscode#139 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
Fission-AI/OpenSpec#1960 ·