forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEphemeralLoop.ql
More file actions
23 lines (21 loc) · 753 Bytes
/
EphemeralLoop.ql
File metadata and controls
23 lines (21 loc) · 753 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/**
* @name Loop body executes at most once
* @description A loop that executes at most once is confusing and should be rewritten
* as a conditional.
* @kind problem
* @problem.severity recommendation
* @id js/single-run-loop
* @tags readability
* @precision low
*/
import javascript
import semmle.javascript.RestrictedLocations
import semmle.javascript.frameworks.Emscripten
from LoopStmt l, BasicBlock body
where
body = l.getBody().getBasicBlock() and
not body.getASuccessor+() = body and
not l instanceof EnhancedForLoop and
// Emscripten generates lots of `do { ... } while(0);` loops, so exclude
not l.getTopLevel() instanceof EmscriptenGeneratedToplevel
select l.(FirstLineOf), "This loop executes at most once."