CWARN.CONSTCOND.WHILE

Condition of while expression is constant

The CWARN.CONSTCOND.WHILE checker finds instances in which the condition of a while statement 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 x = 3;
    while (x = 3)   
    {
      x++;
    } 
 }

Klocwork flags line 3, in which the while condition is constant.