Division and modulo operations are susceptible to divide-by-zero errors. According to C11the C Standard, Section 6.5.5, para. paragraph 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 | ||||||
---|---|---|---|---|---|---|---|---|---|
Include Page | LDRA_V | 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. | ||||||||
Fortify SCA | 5.0 | Can detect violations of this rule with CERT C Rule Pack. | |||||||
| 43 D | Partially implemented. | |||||||
PRQA QA-C |
| 2830 (C) | Fully implemented. |
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
Related Guidelines
...
INT33-CPP. Ensure that division and modulo operations do not result in divide-by-zero errors | |
---|---|
CERT Oracle Secure Coding Standard for Java |
...
...
(Draft) Dividing by zero [divzero] |
MITRE CWE |
...
...
Divide by zero |
...
Bibliography
[Seacord 2005] | Chapter 5, "Integers" |
---|---|
[Warren 2002] | Chapter 2, "Basics" |
...