Skip to content

Commit b541103

Browse files
authored
Merge pull request #9846 from tausbn/python-fix-bad-syntactic_call_count-join
Python: Fix bad join in `syntactic_call_count`
2 parents 0aa64b3 + bdd7719 commit b541103

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

python/ql/lib/semmle/python/pointsto/PointsToContext.qll

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,21 @@ private int max_context_cost() {
2323
}
2424

2525
private int syntactic_call_count(Scope s) {
26-
exists(Function f | f = s and f.getName() != "__init__" |
27-
result =
28-
count(CallNode call |
29-
call.getFunction().(NameNode).getId() = f.getName()
30-
or
31-
call.getFunction().(AttrNode).getName() = f.getName()
32-
)
26+
exists(Function f, string name | f = s and name = f.getName() and name != "__init__" |
27+
result = count(function_call(name)) + count(method_call(name))
3328
)
3429
or
3530
s.getName() = "__init__" and result = 1
3631
or
3732
not s instanceof Function and result = 0
3833
}
3934

35+
pragma[nomagic]
36+
private CallNode function_call(string name) { result.getFunction().(NameNode).getId() = name }
37+
38+
pragma[nomagic]
39+
private CallNode method_call(string name) { result.getFunction().(AttrNode).getName() = name }
40+
4041
private int incoming_call_cost(Scope s) {
4142
/*
4243
* Syntactic call count will often be a considerable overestimate

0 commit comments

Comments
 (0)