Skip to main content

IAR Embedded Workbench for RISC-V 3.40

MISRAC2004-20.3_h

In this section:
Synopsis

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

Enabled by default

Yes

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

A parameter value (>255) might cause a domain or range error. This check is identical to MISRAC2012-Dir-4.11_h.

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:

extern int isalpha(int c);

void leff(int d1, int d2) {
  int e;
  e = isalpha(2512);   /* const not in range */
  e = isalpha(d1);     /* var not checked */
  if(d1 <= 0xFF) {
  } else {
    e = isalpha(d1);   /* checked but in wrong branch */
  }
  if(d1 <= 255) {
    d1 = d2;
    e = isalpha(d1);   /* checked but updated */
  }
}

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

extern int isalpha(int c);

void example(int d) {
  int e;
  if(d <= 255) {
    e = isalpha(d); /* checked before use */
  }
  if(0xFF >= d) {
    e = isalpha(d); /* checked before use */
  }
  if(d > 0xFF) {
  } else {
    e = isalpha(d); /* checked before use */
  }
  if(255 < d) {
  } else {
    e = isalpha(d); /* checked before use */
  }
  e = isalpha('c'); /* constant <= 0xFF */
}