[previous] 2832 [next] Apparent: Division by zero.
Overflow and wraparound

An apparent anomaly has been detected. Preceding operations imply that this expression will sometimes result in division by zero.

For example, in the code shown below, the expression in the "if" statement implies that the value of n is expected to be 0 - sometimes, and so should never be used as a divisor. Of course, if the value of n is never actually zero, the division operation will always be valid; but this would imply that the "if" statement is redundant and any code contained in the "if" block is also redundant.


/*PRQA S 585,2017,2983,2986,3103,3199,3203,3227,3408 ++*/
void foo(int x, int n)
{
   int r;

   if (n == 0)
   {
   }

   r = x / n;                 /* 2832 */
}

See also:

QA·C Source Code Analyser 8.1.2
© 2013 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index Contents