forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringConcatenationInLoop.ql
More file actions
28 lines (25 loc) · 882 Bytes
/
Copy pathStringConcatenationInLoop.ql
File metadata and controls
28 lines (25 loc) · 882 Bytes
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
/**
* @name String concatenation in loop
* @description Concatenating strings in loops has quadratic performance.
* @kind problem
* @tags efficiency
* maintainability
* @problem.severity recommendation
* @sub-severity low
* @precision low
* @id py/string-concatenation-in-loop
*/
import python
predicate string_concat_in_loop(BinaryExpr b) {
b.getOp() instanceof Add and
exists(SsaVariable d, SsaVariable u, BinaryExprNode add |
add.getNode() = b and d = u.getAnUltimateDefinition()
|
d.getDefinition().(DefinitionNode).getValue() = add and
u.getAUse() = add.getAnOperand() and
add.getAnOperand().pointsTo().getClass() = ClassValue::str()
)
}
from BinaryExpr b, Stmt s
where string_concat_in_loop(b) and s.getASubExpression() = b
select s, "String concatenation in a loop is quadratic in the number of iterations."