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

1  void foo() {
2    int x = 3;
3    do {
4      x++;
5    } while (x = 10);  
6 }

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

Fixed code example

1  void foo() {
2    int x = 3;
3    do {
4      x++;
5    } while (<10);             
6 }

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