Do not use the assignment operator in the outermost expression of a selection statement (if
or switch
) or an iteration statement (while
, do
, or for
) because it typically indicates programmer error and can result in unexpected behavior.
Noncompliant Code Example
In this noncompliant code example, an assignment expression is the outermost expression in an if
statement.
...
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
Related Guidelines
...
...
...
...
Likely incorrect |
...
expression [KOA] |
MITRE CWE |
...
...
Use of incorrect operator |
...
Bibliography
[Hatton 1995] | Section 2.7.2, "Errors of |
---|
...
Omission and |
---|
...
Addition" |
---|
...