![]() |
![]() |
2822 | ![]() |
||||
![]() | |||||||
| NULL pointers | |||||||
An apparent anomaly has been detected. Preceding operations imply that this pointer value will sometimes be null. 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 on it will result in undefined behaviour. For example, in the code shown below, the expression in the "if" statement implies that the value of q is expected to be NULL - sometimes, and so it should not be incremented. Of course, if the value of q is never actually NULL, the increment 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 489,508,509,2017,3205,3408,3673,4600 ++*/
#define NULL (void *)0
void foo(int *q)
{
int *p;
if (q == NULL)
{
}
++q; /* 2822 */
}
MISRA-C:2004 Rules applicable to message 2822:
| 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 |