CWARN.CONSTCOND.TERNARY

Condition of ternary conditional expression is constant

The CWARN.CONSTCOND.TERNARY checker finds instances in which the condition of a ternary conditional expression is constant.

Vulnerability and risk

A constant condition for a statement typically results in the program's intention not being accomplished, with probable unexpected consequences.

Vulnerable code example

Copy
  void foo(int a, int b, int x) {
    int x = (x=10) ? a : b;    
  }

Klocwork flags line 2, in which the result of the conditional expression will never change.