Skip to main content

IAR Embedded Workbench for Arm 9.70.x

MISRAC2004-9.1_a

In this section:
Synopsis

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

Enabled by default

Yes

Severity/Certainty

High/High

highhigh.png
Full description

A variable is read before it is assigned a value, on all execution paths. This check is identical to SPC-uninit-var-all, MISRAC++2008-8-5-1_a, MISRAC2012-Rule-9.1_e.

Coding standards
CERT EXP33-C

Do not reference uninitialized memory

CWE 457

Use of Uninitialized Variable

MISRA C:2012 Rule-9.1

(Mandatory) The value of an object with automatic storage duration shall not be read before it has been set

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:

int main(void) {
  int x;
  x++;  //x is uninitialized
  return 0;
}

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

int main(void) {
  int x = 0;
  x++;
  return 0;
}