[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 initialized 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 initialized explicitly before being used or else undefined behavior 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;
}

See also:

QA·C Source Code Analyser 8.1.2
© 2013 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index Contents