Skip to main content

IAR Embedded Workbench for Arm 9.70.x

MISRAC++2023-11.6.2

In this section:
Synopsis

(Mandatory) The value of an object must not be read before it has been set

Enabled by default

Yes

Severity/Certainty

High/Low

highlow.png
Full description

In some execution paths, variables might be read before they are assigned a value. This check is identical to MISRAC++2008-8-5-1_b, MISRAC2004-9.1_b, MISRAC2012-Rule-1.3_k, MISRAC2012-Rule-9.1_f, SPC-uninit-var-some.

Coding standards
CWE 457

Use of Uninitialized Variable

MISRA C:2004 9.1

(Required) All automatic variables shall have been assigned a value before being used.

MISRA C++ 2008 8-5-1

(Required) All variables shall have a defined value before they are used.

Code examples

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

#include <stdlib.h>

int main(void) {
  int x, y;
  if (rand()) {
    x = 0;
  }
  y = x;  //x may not be initialized
  return 0;
}

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

#include <stdlib.h>

int main(void) {
  int x;
  if (rand()) {
    x = 0;
  }
  /* x never read */
  return 0;
}