Skip to main content

IAR Embedded Workbench for RH850 3.20.x

MISRAC2012-Rule-1.3_e

In this section:
Synopsis

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

Enabled by default

Yes

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

A value that is determined using interval analysis to be 0 is used as a divisor. This check is identical to ATH-div-0-interval, MISRAC2004-1.2_g, CERT-INT33-C_d.

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 foo(void)
{
  int a = 1;
  a--;
  return 5 / a;  /* a is 0 */
}

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

int foo(void)
{
  int a = 2;
  a--;
  return 5 / a;  /* OK - a is 1 */
}