[previous] 2820 [next] Constant: Arithmetic operation on NULL pointer.
NULL pointers

Pointer arithmetic is being performed on a null pointer constant.

Internal representation of a null pointer constant is implementation-defined and may not necessarily be bitwise 0. A null pointer constant may be assigned or compared, but any attempt to perform arithmetic operations on it should be viewed as suspicious and non-portable.

For example:


/*PRQA S 489,507,2017,2983,2986,3199,3203,3408,4600 ++*/

#define NULL (void *)0

extern void foo(void)
{
    int *p;

    p = (int *)(NULL) + 1 ;            /* 2820 */
}


MISRA C:2012 Rules applicable to message 2820:

Rule-1.3  (Required) There shall be no occurrence of undefined or critical unspecified behaviour


See also:

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