...
Note that whereas commas serve to delimit multiple arguments in a function call, these commas are not considered comma operators. Multiple arguments of a function call may be evaluated in any order, with no sequence points between each other.
Risk Assessment
Recommendation | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
EXP10-C | Medium | Probable | Medium | P8 | L2 |
Automated Detection
Tool | Version | Checker | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
Astrée |
| evaluation-order | Partially checked | ||||||
Compass/ROSE |
Could detect violations of this recommendation by searching for the following pattern:
| |||||||||
| EVALUATION_ORDER | Can detect the specific instance where a statement contains multiple side effects on the same value with an undefined evaluation order because the statement may behave differently with different compiler flags or different compilers or platforms | |||||||
LDRA tool suite |
| 35 D, 72 D, 1 Q, 134 S | Fully implemented | ||||||
Parasoft C/C++test |
|
|
| MISRA2004-12_2_{a,b,c,d} | Fully implemented | |||||||
PRQA QA-C |
| 3226,3326,0400, 0401, 0402,0403 | Partially implemented | ||||||
RuleChecker |
| evaluation-order | Partially checked | ||||||
PVS-Studio | 6.22 | V521, V681 | General analysis rule set |
A programmer could also violate the recommendation using dynamic memory passed to both functions, but that would be extremely difficult to detect using static analysis.
...
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
Related Guidelines
SEI CERT C++ Coding Standard | EXP50-CPP. Do not depend on the order of evaluation for side effects |
ISO/IEC TR 24772:2013 | Operator Precedence/Order of Evaluation [JCW] Side-effects and Order of Evaluation [SAM] |
MISRA C:2012 | Rule 13.5 (required) |
Bibliography
[ISO/IEC 9899:2011] | Subclause 6.5, "Expressions" |
...
...