V1008. Consider inspecting the 'for' operator. No more than one iteration of the loop will be performed.


The analyzer has detected a possible error that has to do with using suspicious initial and final values of the counter variable in a 'for' statement. This may break the logic of execution.

Consider the following example of suspicious code:

int c = 0;
if (some_condition)
{
  ....
  c = 1;
}
for (int i = 0; i < c; ++i) {
  ....
} 

The loop will iterate either 0 or 1 time; therefore, it can be replaced with an 'if' statement.

int c = 0;
if (some_condition)
{
  ....
  c = 1;
}
if (c != 0)
{
  ....
}

There could also be a mistake in the expression evaluating the value of the variable that the loop counter is compared with. For example, the programmer could have actually meant the following:

int c = 0;
if (some_condition)
{
  ....
  c = 1 + n;
}

for (int i = 0; i < c; ++i)
{
  ....
}

You can look at examples of errors detected by the V1008 diagnostic.


Bugs Found

Checked Projects
355
Collected Errors
13 303