![]() |
![]() |
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:2004 Rules applicable to message 2962:
| Rule 9.1 (Required) | All automatic variables shall have been assigned a value before being used. |
See also:
![]() | ||
| QA·C Source Code Analyser 8.1
MISRA-C:2004 Compliance Module 3.2 © 2012 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index | Contents |