Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 60908de

Browse files
committed
update js/nested-loops-with-same-variable to match cpp
1 parent 20625ae commit 60908de

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

javascript/ql/src/Statements/NestedLoopsSameVariable.ql

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@ import javascript
1515
/**
1616
* Gets an iteration variable that loop `for` tests and updates.
1717
*/
18-
Variable getAnIterationVariable(ForStmt for) {
18+
Variable getAnIterationVariable(ForStmt for, Expr upAccess) {
1919
result.getAnAccess().getParentExpr*() = for.getTest() and
2020
exists(UpdateExpr upd | upd.getParentExpr*() = for.getUpdate() |
21-
upd.getOperand() = result.getAnAccess()
21+
upAccess = upd.getOperand() and upAccess = result.getAnAccess()
2222
)
2323
}
2424

25-
from ForStmt outer, ForStmt inner
25+
from ForStmt outer, ForStmt inner, Variable iteration, Expr upAccess
2626
where
2727
inner.nestedIn(outer) and
28-
getAnIterationVariable(outer) = getAnIterationVariable(inner)
29-
select inner.getTest(), "This for statement uses the same loop variable as an enclosing $@.", outer,
30-
"for statement"
28+
iteration = getAnIterationVariable(outer, _) and
29+
iteration = getAnIterationVariable(inner, upAccess)
30+
select inner.getTest(), "Nested for statement uses loop variable $@ of enclosing $@.", upAccess,
31+
iteration.getName(), outer, "for statement"

0 commit comments

Comments
 (0)