V3020. An unconditional 'break/continue/return/goto' within a loop.

The analyzer has detected a suspicious loop where one of the following statements is used: continue, break, return, goto, or throw. These statements are executed all the time, irrespective of any conditions. For example:

while (k < max)
{                
  if (k == index)
    value = Calculate(k);
  break;
  ++k;
}

In this code, the 'break' statement doesn't belong to the 'if' statement, which will cause it to execute all the time, regardless of whether or not the 'k == index' condition is true, and the loop body will iterate only once. The correct version of this code should look like this:

while (k < max)
{                
  if (k == index)
  {
    value = Calculate(k);
    break;
  }
  ++k;
}

According to Common Weakness Enumeration, potential errors found by using this diagnostic are classified as CWE-670.

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


Bugs Found

Checked Projects
409
Collected Errors
14 072
This website uses cookies and other technology to provide you a more personalized experience. By continuing the view of our web-pages you accept the terms of using these files. If you don't want your personal data to be processed, please, leave this site. Learn More →
Accept