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

Skip to content

Commit 3ffea59

Browse files
committed
Python: Rewrite casts for py/undefined-global-variable
1 parent 81e27aa commit 3ffea59

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

python/ql/src/Variables/UndefinedGlobal.ql

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import semmle.python.pointsto.PointsTo
1717

1818
predicate guarded_against_name_error(Name u) {
1919
exists(Try t | t.getBody().getAnItem().contains(u) |
20-
((Name)((ExceptStmt)t.getAHandler()).getType()).getId() = "NameError"
20+
t.getAHandler().getType().(Name).getId() = "NameError"
2121
)
2222
or
2323
exists(ConditionBlock guard, BasicBlock controlled, Call globals |
@@ -33,7 +33,7 @@ predicate contains_unknown_import_star(Module m) {
3333
exists(ImportStar imp | imp.getScope() = m |
3434
not exists(ModuleObject imported | imported.importedAs(imp.getImportedModuleName()))
3535
or
36-
exists(ModuleObject imported |
36+
exists(ModuleObject imported |
3737
imported.importedAs(imp.getImportedModuleName()) |
3838
not imported.exportsComplete()
3939
)
@@ -42,15 +42,15 @@ predicate contains_unknown_import_star(Module m) {
4242

4343
predicate undefined_use_in_function(Name u) {
4444
exists(Function f | u.getScope().getScope*() = f and
45-
/* Either function is a method or inner function or it is live at the end of the module scope */
46-
(not f.getScope() = u.getEnclosingModule() or ((ImportTimeScope)u.getEnclosingModule()).definesName(f.getName()))
45+
// Either function is a method or inner function or it is live at the end of the module scope
46+
(not f.getScope() = u.getEnclosingModule() or u.getEnclosingModule().(ImportTimeScope).definesName(f.getName()))
4747
and
48-
/* There is a use, but not a definition of this global variable in the function or enclosing scope */
48+
// There is a use, but not a definition of this global variable in the function or enclosing scope
4949
exists(GlobalVariable v | u.uses(v) |
50-
not exists(Assign a, Scope defnScope |
50+
not exists(Assign a, Scope defnScope |
5151
a.getATarget() = v.getAnAccess() and a.getScope() = defnScope |
52-
defnScope = f or
53-
/* Exclude modules as that case is handled more precisely below. */
52+
defnScope = f or
53+
// Exclude modules as that case is handled more precisely below.
5454
(defnScope = f.getScope().getScope*() and not defnScope instanceof Module)
5555
)
5656
)
@@ -120,7 +120,7 @@ predicate first_undefined_use(Name use) {
120120
exists(GlobalVariable v |
121121
v.getALoad() = use |
122122
first_use_in_a_block(use) and
123-
not exists(ControlFlowNode other |
123+
not exists(ControlFlowNode other |
124124
other.getNode() = v.getALoad() and
125125
other.getBasicBlock().strictlyDominates(use.getAFlowNode().getBasicBlock())
126126
)

0 commit comments

Comments
 (0)