Movatterモバイル変換


[0]ホーム

URL:


CodeQL documentation
CodeQL resources

Unsigned comparison to zero

ID: cpp/unsigned-comparison-zeroKind: problemSecurity severity: Severity: warningPrecision: very-highTags:   - maintainability   - readabilityQuery suites:   - cpp-security-and-quality.qls

Click to see the query in the CodeQL repository

This rule finds expressions of the formx>=0 wherex is an unsigned value. This comparison is pointless as it will always yield1.

Recommendation

Check the expression to see whether a different semantics was intended.

Example

typedeflonglongLONGLONG;intf(unsignedintu,LONGLONGl){if(u>0||l>=0)//correct: unsigned value is check for > 0return23;returnu>=0;//wrong: unsigned values are always greater than or equal to 0}

References


[8]ページ先頭

©2009-2025 Movatter.jp