...
While the intent of the code may could be to assign b
to a
and test the value of the result for equality to zero, it is frequently a case of the programmer mistakenly using the assignment operator =
instead of the equals operator ==
.
...
When the assignment is intended, the following compliant solution may be used as because the programmer's intent is clearer:
Code Block | ||
---|---|---|
| ||
if ((a = b) == true) { /* ... */ } |
Although it may could be preferable to express this same logic as an assignment followed by a conditional:
...
Recommendation | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
EXP04-J | low | likely | medium | P6 | L2 |
Related Guidelines
CERT C ++ Secure Coding Standard: EXP19"EXP18-CPPC. Do not perform assignments in conditional expressionsselection statements"
CERT C++ Secure Coding Standard: EXP18"EXP19-CCPP. Do not perform assignments in selection statementsconditional expressions"
ISO/IEC TR 24772 "KOA Likely Incorrect Expressions"
...