python: exclude nonlocals from query

This commit is contained in:
Rasmus Lerchedahl Petersen
2023-03-20 13:34:39 +01:00
parent 9b7a20f4ad
commit 5f438e433d
2 changed files with 1 additions and 2 deletions

View File

@@ -15,7 +15,7 @@ import Undefined
import semmle.python.pointsto.PointsTo
predicate uninitialized_local(NameNode use) {
exists(FastLocalVariable local | use.uses(local) or use.deletes(local) | not local.escapes()) and
exists(FastLocalVariable local | use.uses(local) or use.deletes(local) | not local.escapes() and not local = any(Nonlocal nl).getAVariable()) and
(
any(Uninitialized uninit).taints(use) and
PointsToInternal::reachableBlock(use.getBasicBlock(), _)

View File

@@ -11,5 +11,4 @@
| UninitializedLocal.py:163:7:163:7 | x | Local variable 'x' may be used before it is initialized. |
| UninitializedLocal.py:176:16:176:16 | x | Local variable 'x' may be used before it is initialized. |
| UninitializedLocal.py:178:16:178:16 | y | Local variable 'y' may be used before it is initialized. |
| captured.py:8:15:8:17 | foo | Local variable 'foo' may be used before it is initialized. |
| odasa3987.py:11:8:11:10 | var | Local variable 'var' may be used before it is initialized. |