Skip to main content

IAR Embedded Workbench for RX 5.20

MISRAC2012-Rule-9.1_e

In this section:
Synopsis

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

Enabled by default

Yes

Severity/Certainty

High/High

highhigh.png
Full description

On all execution paths, there is a variable that is read before it is assigned a value. This check is identical to SPC-uninit-var-all, MISRAC2004-9.1_a, MISRAC++2008-8-5-1_a, MISRAC2012-Rule-1.3_j.

Coding standards
CERT EXP33-C

Do not reference uninitialized memory

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:2012 Rule-1.3

(Required) There shall be no occurrence of undefined or critical unspecified behaviour

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;
}