![]() |
![]() |
2933 | ![]() |
||||
![]() | |||||||
| Arrays | |||||||
Dataflow analysis has identified a code construct which is suspicious. An invalid pointer address will sometimes be generated, either in an array subscript operation or by pointer arithmetic. It is possible for a pointer to address any element inside an array and also the element one beyond the end of an array; but the result of computing the address of any other notional element is an 'invalid pointer'. A scalar object can be considered as equivalent to an array dimensioned to 1. Notice that the action of computing an invalid pointer is classified as undefined behavior even if the pointer is not actually being dereferenced. This will happen in the example below unless the parameter 'n' is greater than 0.
/*PRQA S 488,2017,2982,2983,2986,3120,3132,3199,3203,3227,3408,3447,3692 ++*/
extern int a[10];
void foo(int n)
{
int *p;
int i;
int x = 11;
for (i = 0; i < n; ++i)
{
--x;
}
p = &a[x]; /* 2933 */
}
See also:
![]() | ||
| QA·C Source Code Analyser 8.1.2
© 2013 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | Contents |