CWARN.CONSTCOND.DO

Condition of do statement is constant

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

In this example, Klocwork flags line 5, in which the condition (x=10) is constant.

Fixed code example

Copy
  void foo() {
    int x = 3;
    do {
      x++;
    } while (<10);             
 }

In the fixed example, the condition is no longer a constant.