-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathLeakingListComprehension.ql
More file actions
31 lines (29 loc) · 1.07 KB
/
LeakingListComprehension.ql
File metadata and controls
31 lines (29 loc) · 1.07 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 List comprehension variable used in enclosing scope
* @description Using the iteration variable of a list comprehension in the enclosing scope will result in different behavior between Python 2 and 3 and is confusing.
* @kind problem
* @tags portability
* correctness
* @problem.severity warning
* @sub-severity high
* @precision very-high
* @id py/leaking-list-comprehension
*/
import python
import Definition
from ListComprehensionDeclaration l, Name use, Name defn
where
use = l.getALeakedVariableUse() and
defn = l.getDefinition() and
l.getAFlowNode().strictlyReaches(use.getAFlowNode()) and
/* Make sure we aren't in a loop, as the variable may be redefined */
not use.getAFlowNode().strictlyReaches(l.getAFlowNode()) and
not l.contains(use) and
not use.deletes(_) and
not exists(SsaVariable v |
v.getAUse() = use.getAFlowNode() and
not v.getDefinition().strictlyDominates(l.getAFlowNode())
)
select use,
use.getId() + " may have a different value in Python 3, as the $@ will not be in scope.", defn,
"list comprehension variable"