C and C++


LANG.STRUCT.SE.COND : Condition Contains Side Effects

Summary

A condition may change the state of the program if evaluated.

Note: pre/post-increment (++) and pre/post-decrement (--) operations will only trigger a warning of this class if they occur on the RHS of a logical expression.

See also Too Many Side Effects in Condition.

Properties

Class Name Condition Contains Side Effects
Significance style
Mnemonic LANG.STRUCT.SE.COND
Categories
CWE CWE:710 Improper Adherence to Coding Standards
CERT-C CERT-C:EXP45-C Do not perform assignments in selection statements
JPL JPL:19 Do not use expressions with side effects.
Availability Available for C and C++.
Enabling Checks for this warning class are disabled by default, and require the unnormalized C ASTs for the project. To enable them, add the following WARNING_FILTER rule and RETAIN_UNNORMALIZED_C_AST specification to the project configuration file.
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Condition Contains Side Effects"
Note that retaining the unnormalized ASTs will increase the disk space used to store the project representation, and may make the analysis take longer.

Example

int lang_struct_se_cond(int i, int *p){
    if (p && i-- > 0) {   /* 'Condition Contains Side Effects' warning issued here */
        return *p;
    }
    return i;
}

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.