Skip to main content

IAR Embedded Workbench for RX 5.20

MISRAC2004-20.3_e

In this section:
Synopsis

(Required) The validity of values passed to library functions shall be checked (<1 case).

Enabled by default

Yes

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

A parameter value (>=1) might cause domain or range error. This check is identical to MISRAC2012-Dir-4.11_e.

Coding standards
MISRA C:2004 20.3

(Required) The validity of values passed to library functions shall be checked.

MISRA C:2012 Dir-4.11

(Required) The validity of values passed to library functions shall be checked

Code examples

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

#include <math.h>

void lt1(double d1, double d2) {
  double e;
  e = atanh(2.0);      /* const not in range */
  e = atanh(d1);     /* var not checked */
  if(d1 < 1) {
  } else {
    e = atanh(d1);   /* checked but in wrong branch */
  }
  if(d1 < 1) {
    d1 = d2;
    e = atanh(d1);   /* checked but updated */
  }
}

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

#include<math.h>

void example(double d) {
  double e;
  if(d < 1) {
    e = atanh(d); /* checked before use */
  }
  if(0 > d) {
    e = atanh(d); /* checked before use */
  }
  if(d >= 1) {
  } else {
    e = atanh(d); /* checked before use */
  }
  if(1 <= d) {
  } else {
    e = atanh(d); /* checked before use */
  }
  e = atanh(0.5); /* constant < 1 */
}