Skip to main content

IAR Embedded Workbench for Arm 9.70.x

ATH-div-0-unchk-global

In this section:
Synopsis

A global variable is used as a divisor without having been determined to be non-zero.

Enabled by default

Yes

Severity/Certainty

Medium/Low

mediumlow.png
Full description

A global variable is used as a divisor without having been determined to be non-zero. This will cause a 'divide by zero' runtime error if the variable has a value of 0. This check is identical to MISRAC2004-1.2_i, MISRAC2012-Rule-1.3_g, CERT-INT33-C_f.

Coding standards
CERT INT33-C

Ensure that division and modulo operations do not result in divide-by-zero errors

CWE 369

Divide By Zero

MISRA C:2004 1.2

(Required) No reliance shall be placed on undefined or unspecified behavior.

MISRA C:2012 Rule-1.3

(Required) There shall be no occurrence of undefined or critical unspecified behaviour

Code examples

The following code example fails the check and will give a warning:

int x;

int example() {
  return 5/x;
}

The following code example passes the check and will not give a warning about this issue:

int x;

int example() {
  if (x != 0){
    return 5/x;
  }
}