GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — codeql/python/ql/src/Statements/NestedLoopsSameVariable.ql at main · github/codeql Expand file tree/ Copy pathNestedLoopsSameVariable.qlMore file actions 31 lines (27 loc) · 1.11 KB / Copy pathNestedLoopsSameVariable.qlFile metadata and controls31 lines (27 loc) · 1.11 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 /** * @name Nested loops with same variable * @description Nested loops in which the target variable is the same for each loop make * the behavior of the loops difficult to understand. * @kind problem * @tags quality * maintainability * readability * @problem.severity recommendation * @sub-severity high * @precision very-high * @id py/nested-loops-with-same-variable */ import python predicate loop_variable(For f, Variable v) { f.getTarget().defines(v) } predicate variableUsedInNestedLoops(For inner, For outer, Variable v) { /* Only treat loops in body as inner loops. Loops in the else clause are ignored. */ outer.getBody().contains(inner) and loop_variable(inner, v) and loop_variable(outer, v) and /* Ignore cases where there is no use of the variable or the only use is in the inner loop */ exists(Name n | n.uses(v) and outer.contains(n) and not inner.contains(n)) } from For inner, For outer, Variable v where variableUsedInNestedLoops(inner, outer, v) select inner, "Nested for statement uses loop variable '" + v.getId() + "' of enclosing $@.", outer, "for statement" |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |