ATH-div-0-unchk-param
In this section:
Synopsis
A parameter is used as a divisor without having been determined to be non-zero.
Enabled by default
Yes
Severity/Certainty
Medium/Low

Full description
A parameter is used as a divisor without having been determined to be non-zero. This will cause a 'divide by zero' runtime error if the parameter has a value of 0. This check is identical to CERT-INT33-C_h.
Coding standards
- CERT INT33-C
Ensure that division and modulo operations do not result in divide-by-zero errors
- CWE 369
Divide By Zero
Code examples
The following code example fails the check and will give a warning:
int example(int x) {
return 5/x;
}
The following code example passes the check and will not give a warning about this issue:
int example(int x) {
if (x != 0){
return 5/x;
}
}