[previous] 2812 [next] Apparent: Dereference of NULL pointer.
NULL pointers

An apparent anomaly has been detected. Preceding operations imply that this pointer value will sometimes be NULL. The result of any attempt to dereference a null pointer value is undefined.

For example, in the code shown below, the expression in the "if" statement implies that the value of p is expected to be NULL - sometimes, and so it should not be dereferenced. Of course, if the value of p is never actually NULL, the dereference operation will always be valid; but this would imply that the "if" statement is redundant and any code contained in the "if" block is also redundant.


/*PRQA S 505,2017,2983,2986,3199,3203,3227,3408,3412,3673,4600 ++*/
#define NULL (void *)0

void foo(int *p)
{
    int r;

    if (p == NULL)
    {
    }

    r = *p;                 /* 2812 */
}

See also:

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