mirror of
https://github.com/github/codeql.git
synced 2026-04-23 15:55:18 +02:00
update js/nested-loops-with-same-variable to match cpp
This commit is contained in:
@@ -15,16 +15,17 @@ import javascript
|
||||
/**
|
||||
* Gets an iteration variable that loop `for` tests and updates.
|
||||
*/
|
||||
Variable getAnIterationVariable(ForStmt for) {
|
||||
Variable getAnIterationVariable(ForStmt for, Expr upAccess) {
|
||||
result.getAnAccess().getParentExpr*() = for.getTest() and
|
||||
exists(UpdateExpr upd | upd.getParentExpr*() = for.getUpdate() |
|
||||
upd.getOperand() = result.getAnAccess()
|
||||
upAccess = upd.getOperand() and upAccess = result.getAnAccess()
|
||||
)
|
||||
}
|
||||
|
||||
from ForStmt outer, ForStmt inner
|
||||
from ForStmt outer, ForStmt inner, Variable iteration, Expr upAccess
|
||||
where
|
||||
inner.nestedIn(outer) and
|
||||
getAnIterationVariable(outer) = getAnIterationVariable(inner)
|
||||
select inner.getTest(), "This for statement uses the same loop variable as an enclosing $@.", outer,
|
||||
"for statement"
|
||||
iteration = getAnIterationVariable(outer, _) and
|
||||
iteration = getAnIterationVariable(inner, upAccess)
|
||||
select inner.getTest(), "Nested for statement uses loop variable $@ of enclosing $@.", upAccess,
|
||||
iteration.getName(), outer, "for statement"
|
||||
|
||||
Reference in New Issue
Block a user