![]() |
![]() |
2813 | ![]() |
||||
![]() | |||||||
| NULL pointers | |||||||
Dataflow analysis has identified a code construct which is suspicious. The code may be entirely safe but further investigation is advisable. A pointer value is being dereferenced and examination of the immediate context suggests that the pointer value could sometimes be NULL. The result of any attempt to dereference a null pointer value is undefined. For example, in the code shown below, the pointer 'p' being dereferenced in the 'return' statement, will be NULL unless the parameter 'n' is greater than 0.
/*PRQA S 505,2017,2986,3132,3199,3203,3227,3408,3412,3447,3673,4600 ++*/
#define NULL (void *)0
extern int ar[100];
extern int foo(int n)
{
int i;
int *p = NULL;
for (i = 0; i < n; ++i)
{
p = &ar[i];
}
return *p; /* 2813 */
}
No MISRA C:2012 Rules applicable to message 2813
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 |