[previous] 2973 [next] Suspicious: Passing address of uninitialized object '%s' to a function parameter declared as a pointer to const.
Unset data

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

A pointer which could be addressing unset data is being passed as an argument to a function. However the function parameter is declared as a pointer to a const qualified type and if it is dereferenced, the result will be undefined.

It may be appropriate to pass a pointer to some uninitialized data as an argument to a function that will then initialize the data. However, it can never be appropriate to pass such a pointer to a function if the corresponding parameter is declared as a pointer to a const qualified type, because no initialization is possible.

For example:


/*PRQA S 2017,3196,2986,3199,3203,3204,3227,3354,3408,3447,3602 ++*/

extern void foo(const int *p);

void test(int n, int p)
{
    int a;

    while (n > 0)
    {
        a = p;
        --n;
    }

    /* "a" will remain unset if the parameter n was
     *  passed with a zero or negative value           */

    foo(&a);                       /* 2973 */
}

See also:

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