MISRAC++2008-8-5-1_a
In this section:
Synopsis
(Required) All variables shall have a defined value before they are used.
Enabled by default
Yes
Severity/Certainty
High/High

Full description
In all execution paths, variables are read before they are assigned a value. This check is identical to SPC-uninit-var-all, MISRAC2004-9.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:2004 9.1
(Required) All automatic variables shall have been assigned a value before being used.
- 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:
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;
}