![]() |
![]() |
2823 | ![]() |
||||
![]() | |||||||
| NULL pointers | |||||||
Dataflow analysis has identified a code construct which is suspicious. The code may be entirely safe but further investigation is advisable. An arithmetic operation is being performed on a pointer value. Examination of the immediate context suggests that the pointer value could sometimes be NULL. A null pointer may be assigned or compared, but any attempt to perform arithmetic operations on it will result in undefined behavior. For example, in the code shown below, the pointer 'p' which is being incremented, will be NULL unless the parameter 'n' is greater than 0.
/*PRQA S 489,505,2017,2983,2986,3132,3199,3203,3227,3408,3412,3447,3673,4600 ++*/
#define NULL (void *)0
extern int ar[100];
extern void foo(int n)
{
int i;
int *p = NULL;
for (i = 0; i < n; ++i)
{
p = &ar[i];
}
p++; /* 2823 */
}
See also:
![]() | ||
| QA·C Source Code Analyser 8.1.2
© 2013 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | Contents |