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

Skip to content

Commit 6a5ec51

Browse files
committed
Update IsComparisons.qll to account for not tracking attributes in detail.
1 parent 5551143 commit 6a5ec51

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

python/ql/src/Expressions/IsComparisons.qll

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,14 @@ predicate invalid_portable_is_comparison(Compare comp, Cmpop op, ClassObject cls
104104
/* OK to use 'is' when comparing items from a known set of objects */
105105
not exists(Expr left, Expr right, Object obj |
106106
comp.compares(left, op, right) and
107-
left.refersTo(obj) and right.refersTo(obj) and
108-
exists(ImmutableLiteral il | il.getLiteralObject() = obj)
107+
exists(ImmutableLiteral il | il.getLiteralObject() = obj) |
108+
left.refersTo(obj) and right.refersTo(obj)
109+
or
110+
/* Simple constant in module, probably some sort of sentinel */
111+
exists(AstNode origin |
112+
not left.refersTo(_) and right.refersTo(obj, origin) and
113+
origin.getScope().getEnclosingModule() = comp.getScope().getEnclosingModule()
114+
)
109115
)
110116
and
111117
/* OK to use 'is' when comparing with a member of an enum */

0 commit comments

Comments
 (0)