@@ -27,8 +27,6 @@ class DangerousWhileLoop extends WhileStmt {
27
27
not exp instanceof PointerFieldAccess and
28
28
not exp instanceof ValueFieldAccess and
29
29
exp .( VariableAccess ) .getTarget ( ) .getName ( ) = dl .getName ( ) and
30
- not exp .getParent * ( ) instanceof CrementOperation and
31
- not exp .getParent * ( ) instanceof Assignment and
32
30
not exp .getParent * ( ) instanceof FunctionCall
33
31
}
34
32
@@ -37,10 +35,10 @@ class DangerousWhileLoop extends WhileStmt {
37
35
/** Holds when there are changes to the variables involved in the condition. */
38
36
predicate isUseThisVariable ( ) {
39
37
exists ( Variable v |
40
- exp .( VariableAccess ) .getTarget ( ) = v and
38
+ this . getCondition ( ) . getAChild * ( ) .( VariableAccess ) .getTarget ( ) = v and
41
39
(
42
40
exists ( Assignment aexp |
43
- aexp = this . getStmt ( ) .getAChild * ( ) and
41
+ this = aexp . getEnclosingStmt ( ) .getParentStmt * ( ) and
44
42
(
45
43
aexp .getLValue ( ) .( ArrayExpr ) .getArrayBase ( ) .( VariableAccess ) .getTarget ( ) = v
46
44
or
@@ -49,7 +47,7 @@ class DangerousWhileLoop extends WhileStmt {
49
47
)
50
48
or
51
49
exists ( CrementOperation crm |
52
- crm = this . getStmt ( ) .getAChild * ( ) and
50
+ this = crm . getEnclosingStmt ( ) .getParentStmt * ( ) and
53
51
crm .getOperand ( ) .( VariableAccess ) .getTarget ( ) = v
54
52
)
55
53
)
@@ -59,4 +57,4 @@ class DangerousWhileLoop extends WhileStmt {
59
57
60
58
from DangerousWhileLoop lp
61
59
where not lp .isUseThisVariable ( )
62
- select lp .getDeclaration ( ) , "A variable with this name is used in the loop condition."
60
+ select lp .getDeclaration ( ) , "A variable with this name is used in the $@ condition." , lp , "loop "
0 commit comments