Division and modulo operations are susceptible to divide-by-zero errors. According to C11, Section 6.5.5, para. 5 [ISO/IEC 9899:2011],
The result of the
/
operator is the quotient from the division of the first operand by the second; the result of the%
operator is the remainder. In both operations, if the value of the second operand is zero, the behavior is undefined.
...
Tool | Version | Checker | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
| 43 D | Partially implemented. | |||||||
Fortify SCA | V. 5.0 | Can detect violations of this rule with CERT C Rule Pack. | |||||||
Compass/ROSE | Can detect some violations of this rule. In particular, it ensures that all operations involving division or modulo are preceded by a check ensuring that the second operand is nonzero. |
...
CERT Oracle Secure Coding Standard for Java: NUM02-J. Ensure that division and modulo operations do not result in divide-by-zero errors
ISO/IEC 9899:2011 Section Section 6.5.5, "Multiplicative operators"
...