[previous] 2821 [next] Definite: Arithmetic operation on NULL pointer.
NULL pointers

A definite anomaly has been detected. Examination of the context indicates that this expression will always result in an arithmetic operation involving a null pointer.

The internal representation of a null pointer is implementation-defined and may not necessarily be bitwise 0. A null pointer may be assigned or compared, but any attempt to perform arithmetic operations will result in undefined behaviour.

For example


/*PRQA S 489,508,2017,3205,3408,3673,4600 ++*/
#define NULL (void *)0

void foo(int *q)
{
    int *p;

    if (q == NULL)
    {
        ++q;                /* 2821 */
    }
}


MISRA-C:2004 Rules applicable to message 2821:

Rule  21.1  (Required) Minimisation of run-time failures shall be ensured by the use of at least one of (a) static analysis tools/techniques; (b) dynamic analysis tools/techniques; (c) explicit coding of checks to handle run-time faults


See also:

QA·C Source Code Analyser 8.1
MISRA-C:2004 Compliance Module 3.2
© 2012 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index Contents