[previous] 2824 [next] Possible: Arithmetic operation on NULL pointer.
NULL pointers

A possible dataflow condition has been identified.

A null pointer may be assigned or compared, but any attempt to perform arithmetic operations on it will result in undefined behavior. Be aware that the internal representation of a null pointer constant is implementation-defined and may not necessarily be bitwise 0.

For example:


/*PRQA S 489,510,2017,2983,2986,3199,3205,3408,3673,4600 ++*/
#define NULL (void *)0

void foo(int *p, int *q)
{
    p++;                        /* 2824 */ /* p could be a null pointer */

    if (q != NULL)
    {
        ++q;                    /* ...  */ /* q is NOT a null pointer at this point */
    }
}

See also:

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