![]() |
![]() |
2962 | ![]() |
||||
![]() | |||||||
| Unset data | |||||||
An apparent anomaly has been detected. Preceding operations imply that this object will sometimes be uninitialized and its value may therefore be undefined. For example, in the code shown below, the value of i will only be initialized if the value of n is greater than 0. However the presence of the "if" statement implies that this will not always be true. Of course, if the value of n is always greater than zero, the value of i will always be initialized; but this would imply that the "if" statement is redundant and any code contained in the "if" block should be moved to the outer block.
/*PRQA S 2017,2983,2986,3120,3199,3203,3227,3347,3408 ++*/
void foo(int n)
{
int i;
int j;
if (n > 0)
{
i = 1;
}
j = i + 2; /* 2962 */
}
MISRA C:2012 Rules applicable to message 2962:
| Rule-9.1 (Mandatory) | The value of an object with automatic storage duration shall not be read before it has been set |
See also:
![]() | ||
| QA·C Source Code Analyser 8.1
MISRA C:2012 Compliance Module 1.0 © 2012 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index | Contents |