MISRAC2004-1.2_a
Synopsis
(Required) No reliance shall be placed on undefined or unspecified behavior. This is a semi-equivalent initialization check for arrays, which ensures that at least one element of the array has been written before any element is attempted to be read. A warning generally means that you have read an uninitialized value, which might cause the application to behave erroneously or crash.
Enabled by default
Yes
Severity/Certainty
High/Medium

Full description
There are read accesses from local buffers that are not preceded by write accesses. This check is identical to MISRAC2012-Rule-9.1_b, SPC-uninit-arr-all, CERT-EXP33-C_d.
Coding standards
- CERT EXP33-C
Do not reference uninitialized memory
- CWE 457
Use of Uninitialized Variable
- MISRA C:2004 1.2
(Required) No reliance shall be placed on undefined or unspecified behavior.
- 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
Code examples
The following code example fails the check and will give a warning:
void example() {
int a[20];
int b = a[1];
}
The following code example passes the check and will not give a warning about this issue:
extern void f(int*);
void example() {
int a[20];
f(a);
int b = a[1];
}