V609. Divide or mod by zero.


The analyzer has detected a situation when division by zero may occur.

Consider this sample:

for (int i = -10; i != 10; ++i)
{
  Foo(X / i);
}

While executing the loop, the 'i' variable will acquire a value equal to 0. At this moment, an operation of division by zero will occur. To fix it we need to specifically handle the case when the 'i' iterator equals zero.

This is the correct code:

for (int i = -10; i != 10; ++i)
{
  if (i != 0)
    Foo(X / i);
}

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

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


Bugs Found

Checked Projects
355
Collected Errors
13 303