Movatterモバイル変換


[0]ホーム

URL:


CodeQL documentation
CodeQL resources

Inconsistent direction of for loop

ID: cpp/inconsistent-loop-directionKind: problemSecurity severity: Severity: errorPrecision: highTags:   - correctness   - external/cwe/cwe-835Query suites:   - cpp-security-and-quality.qls

Click to see the query in the CodeQL repository

Afor-loop iteration expression goes backwards with respect of the initialization statement and condition expression.

This warning indicates that afor-loop might not function as intended.

Recommendation

To fix this issue, check that the loop condition is correct and change the iteration expression to match.

Example

In the following example, the initialization statement (i=0) and the condition expression (i<100) indicate that the intended iteration expression should have been incrementing, but instead a postfix decrement operator is used (i--).

voidf(){for(signedchari=0;i<100;i--){// code ...}}

To fix this issue, change the iteration expression to match the direction of the initialization statement and the condition expression:i++.

References


[8]ページ先頭

©2009-2025 Movatter.jp