Skip to content

Commit 2116400

Browse files
committed
Refine LegacyForLoopCondition
1 parent 82f9adc commit 2116400

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

cpp/common/src/codingstandards/cpp/Loops.qll

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,12 +389,21 @@ class LegacyForLoopCondition extends RelationalOperation {
389389
Expr loopBound;
390390

391391
LegacyForLoopCondition() {
392-
loopCounter = this.getAnOperand().getAChild*() and
393-
loopBound = this.getAnOperand() and
394-
loopCounter.getTarget() = getAnIterationVariable(forLoop) and
395-
loopBound != loopCounter
392+
this = forLoop.getCondition() and
393+
exists(Expr loopCounterExpr |
394+
loopCounterExpr = this.getAnOperand() and
395+
loopBound = this.getAnOperand() and
396+
loopCounter = loopCounterExpr.getAChild*() and
397+
loopCounter.getTarget() = getAnIterationVariable(forLoop) and
398+
loopBound != loopCounterExpr
399+
)
396400
}
397401

402+
/**
403+
* Gets the for-loop this expression is a termination condition of.
404+
*/
405+
ForStmt getForLoop() { result = forLoop }
406+
398407
/**
399408
* Gets the variable access to the loop counter variable, appearing in this loop condition.
400409
*/

0 commit comments

Comments
 (0)