Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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
Include Page
Astrée_V
Astrée_V
CERT.EXP.10
evaluation-order
multiple-volatile-accesses
Partially checked
Axivion Bauhaus Suite

Include Page
Axivion Bauhaus Suite_V
Axivion Bauhaus Suite_V

CertC-EXP10Fully implemented
CodeSonar
Include Page
CodeSonar_V
CodeSonar_V

LANG.STRUCT.SE.IOE

Indeterminate Order of Evaluation
Partially checked
Compass/ROSE

 

 



Could detect violations of this recommendation by searching for the following pattern:

    • Any expression that calls two functions between the same sequence points
    • Those two functions both modify the value of a static variable
    • That static variable's value is referenced by code following the expression

Coverity

Include Page
Coverity_V
Coverity_V

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

Helix QAC

Include Page
Helix QAC_V
Helix QAC_V

C0400, C0401, C0402, C0403, C0404, C0405, C3226, C3326


LDRA tool suite
Include Page
LDRA_V
LDRA_V
35 D, 72 D, 1 Q, 134 S

Fully implemented

Parasoft C/C++test
9.5MISRA2004-12_2_{a,b,c,d}Fully implementedPRQA QA-C Include PagePRQA QA-C_vPRQA QA-C_v3226,3326,0400, 0401, 0402,0403
Include Page
Parasoft_V
Parasoft_V

CERT_C-EXP10-a
CERT_C-EXP10-b
CERT_C-EXP10-c
CERT_C-EXP10-d

The value of an expression shall be the same under any order of evaluation that the standard permits
Don't write code that depends on the order of evaluation of function arguments
Don't write code that depends on the order of evaluation of function designator and function arguments
Don't write code that depends on the order of evaluation of expression that involves a function call

PC-lint Plus

Include Page
PC-lint Plus_V
PC-lint Plus_V

564, 931

Partially supported

Polyspace Bug Finder

Include Page
Polyspace Bug Finder_V
Polyspace Bug Finder_V

CERT C: Rec. EXP10-C

Checks for situations where expression value depends on order of evaluation or side effects (rec. fully covered)

PVS-Studio

Include Page
PVS-Studio_V
PVS-Studio_V

V521, V681
Partially implemented

RuleChecker
Include Page
RuleChecker_V
RuleChecker_V
CERT.EXP.10
evaluation-order
multiple-volatile-accesses
Partially checked

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 StandardEXP50-CPP. Do not depend on the order of evaluation for side effects
ISO/IEC TR 24772:2013Operator Precedence/Order of Evaluation [JCW]
Side-effects and Order of Evaluation [SAM]
MISRA C:2012Rule 13.5 (required)

Bibliography

[ISO/IEC 9899:2011]Subclause 6.5, "Expressions"

...


...

Image Modified Image Modified Image Modified