Movatterモバイル変換


[0]ホーム

URL:


CodeQL documentation
CodeQL resources

Comparison where assignment was intended

ID: cpp/compare-where-assign-meantKind: problemSecurity severity: Severity: errorPrecision: highTags:   - reliability   - correctness   - external/cwe/cwe-482Query suites:   - cpp-security-and-quality.qls

Click to see the query in the CodeQL repository

This rule finds uses of the equality operator== in places where the assignment operator= would make more sense. This is a common mistake in C and C++, because of the similarity of the= and the== operator, and the fact that expressions are valid as top-level statements.

The rule flags every occurrence of an equality operator in a position where its result is discarded.

Recommendation

Check to ensure that the flagged expressions are not typos. If the result of an equality test is really intended to be discarded, it should be explicitly cast tovoid.

Example

intx;x==4;// most likely = was intended. Otherwise this statement has no effect....

References


[8]ページ先頭

©2009-2025 Movatter.jp