MISRAC++2008-5-14-1
Synopsis
(Required) The right hand operand of a logical && or || operator shall not contain side effects.
Enabled by default
Yes
Severity/Certainty
Medium/Medium

Full description
There are right-hand operands of && or || operators that contain side effects. This check is identical to MISRAC2004-12.4, MISRAC2012-Rule-13.5, MISRAC++2023-8.14.1.
Coding standards
- CWE 768
Incorrect Short Circuit Evaluation
- MISRA C:2004 12.4
(Required) The right-hand operand of a logical && or || operator shall not contain side effects.
- MISRA C:2012 Rule-13.5
(Required) The right hand operand of a logical && or || operator shall not contain persistent side effects
- MISRA C++ 2023 8.14.1
(Advisory) The right-hand operand of a logical && or || operator should not contain persistent side effects
Code examples
The following code example fails the check and will give a warning:
#include <stdlib.h>
void example(void) {
int i;
int size = rand() && i++;
}
The following code example passes the check and will not give a warning about this issue:
#include <stdlib.h>
void example(void) {
int i;
int size = rand() && i;
}