Why is this an issue?
Any statement (other than a null statement, which means a statement containing only a semicolon ;
) which has no side effect and does
not result in a change of control flow will normally indicate a programming error, and therefore should be refactored.
Noncompliant code example
int func(int a, int b) {
int result = 0;
a + b; // Noncompliant, no side effect.
return result;
}
Compliant solution
int func(int a, int b) {
int result = a + b; // Compliant
return result;
}
Resources
- MITRE, CWE-482 - Comparing instead of Assigning
- MISRA C:2004, 14.2 - All non-null statements shall either have at least one side-effect however executed, or cause control flow to change.