
Type: Bug Detection

Status: Active

Resolution: Unresolved

Labels:

Message:Make sure 'xxxxx' can't be zero before doing this [divisionmodulation].

Highlighting:

Default Severity:Critical

Impact:High

Likelihood:Low

Default Quality Profiles:Sonar way

Targeted languages:C#, Flex, JavaScript, ObjectiveC, PHP, PL/SQL, Swift, VB.Net

Covered Languages:C, C++, Java

Remediation Function:Constant/Issue

Constant Cost:5 min

Analysis Scope:Main Sources, Test Sources

Implementation details:

CERT:NUM02J., INT33C.

CWE:CWE369

CPPCheck:zerodiv
If the denominator to a division or modulo operation is zero it would result in a fatal error.
Noncompliant Code Example
void test_divide() { int z = 0; if (unknown()) { // .. z = 3; } else { // .. } z = 1 / z; // Noncompliant, possible division by zero }
Compliant Solution
void test_divide() { int z = 0; if (unknown()) { // .. z = 3; } else { // .. z = 1; } z = 1 / z; }
See
 MITRE, CWE369  Divide by zero
 CERT, NUM02J.  Ensure that division and remainder operations do not result in dividebyzero errors
 CERT, INT33C.  Ensure that division and remainder operations do not result in dividebyzero errors
 is implemented by

SONARPHP1012 Add S3518: Zero should not be a possible denominator
 Open

CPP209 C Rule: Zero should not be a possible denominator
 Closed

CPP1678 C++ Rule: Zero should not be a possible denominator
 Closed

CPP2312 Add 12 rules for ObjectiveC based on symbolic execution
 Closed

SONARJAVA1762 Rule S3518: Zero should not be a possible denominator
 Closed
 is related to

SONARJAVA2410 Issue filter should also filter rules depending of the java warning suppressed
 Closed

SONARJAVA3026 S3518 Division by zero on floats and double should not mention ArithmeticException
 Closed

SONARJAVA3345 S3518 (division by zero) should handle BigDecimal and BigInteger
 Closed

RSPEC3652 Zero should not be a possible denominator in a "WHERE" clause
 Active
1.

CFamily: Zero should not be a possible denominator  RSPEC3594  Active  Unassigned  
2.

Java  RSPEC5938  Active  Unassigned 