[previous] 2963 [next] Suspicious: Using value of uninitialized automatic object '%s'.
Unset data

Dataflow analysis has identified a code construct which is suspicious. The code may be entirely safe but further investigation is advisable.

Dataflow analysis is unable to be sure that this variable is always initialised at this point. Variables with static storage duration are initialized to zero by default. Automatic variables (i.e. variables that are defined at block scope without the keyword static) must be initialised explicitly before being used or else undefined behaviour will result.

In the code shown below, for example, the variable 'a' will be unset when it is assigned to 'x' if the while loop has been bypassed. This will happen if the parameter 'n' is not greater than zero.


/*PRQA S 2017,3227,3353,3408 ++*/

int foo(int n, int p)
{
    int a;
    int x;
    int i;

    for (i = 0; i < n; ++i)
    {
        a = p;
    }
    
    /* "a" could remain unset at this point if the parameter n was
     *  passed with a zero or negative value . Is this possible ?  */

    x = a;                     /* 2963 */

    return x;
}


No MISRA C:2012 Rules applicable to message 2963


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