Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Edited by sciSpider $version (sch jbop) (X_X)@==(Q_Q)@

...

This recommendation is related to EXP30-C. Do not depend on order of evaluation between sequence points, but focuses on behavior that is non-portable or potentially confusing.

...

Noncompliant Code Example

The order of evaluation of the function designator, the actual arguments, and subexpressions within the actual arguments is unspecified, but there is a sequence point before the actual call.

...

Consequently, the result of the following non-compliant noncompliant code depends upon unspecified behavior:

...

This code may result in g being assigned the value 1, or equally likely, being assigned the value 2.

Compliant Solution

This compliant solution is independent of the order of evaluation of the operands and can only be interpreted in one way.

...

This code always results in g being assigned the value 2.

Exceptions

EXP10-EX1: The && and || operators guarantee left-to-right evaluation; there is a sequence point after the evaluation of the first operand.

...

Note that while 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 in between each other.

Risk Assessment

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

EXP10-A C

medium

probable

medium

P8

L2

Related Vulnerabilities

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

References

Wiki Markup
\[[ISO/IEC 9899:1999|AA. C References#ISO/IEC 9899-1999]\] Section 6.5, "Expressions," Section 6.5.16, "Assignment operators," Section 6.5.2.2, "Function calls," and Section 6.7.8, "Initialization"
\[[ISO/IEC PDTR 24772|AA. C References#ISO/IEC PDTR 24772]\] "JCW Operator precedence/Order of Evaluation" and "SAM Side-effects and order of evaluation"
\[[MISRA 04|AA. C References#MISRA 04]\] Rule 12.2

...

      03. Expressions (EXP)       EXP11-AC. Do not apply operators expecting one type to data of an incompatible type