MISRAC2004-12.4
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
Right-hand operands of && or || were found that contain side effects. This check is identical to MISRAC++2008-5-14-1, MISRAC2012-Rule-13.5, MISRAC++2023-8.14.1.
Coding standards
- CWE 768
Incorrect Short Circuit Evaluation
- MISRA C:2012 Rule-13.5
(Required) The right hand operand of a logical && or || operator shall not contain persistent side effects
- MISRA C++ 2008 5-14-1
(Required) The right hand operand of a logical && or || operator shall not contain 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;
}