Skip to main content

IAR Embedded Workbench for RL78 5.20

MISRAC2012-Dir-4.14_h

In this section:
Synopsis

(Required) The validity of values received from external sources shall be checked.

Enabled by default

Yes

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

A user-controlled value is used as part of a loop condidition.

Coding standards
MISRA C:2012 Dir-4.14

(Required) The validity of values received from external sources shall be checked

Code examples

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

void example(void) {
  int a;
  int i = 0;
  scanf("%d", &a);
  while (i < a) {
    i++;
  }  
}

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

void example(void) {
  int a;
  int i = 0;
  scanf("%d", &a);
  if (a > 0 && a < 10) {
    while (i < a) {
      i++;
    }   
  }
}