![]() |
![]() |
2932 | ![]() |
||||
![]() | |||||||
| Arrays | |||||||
An apparent anomaly has been identified. 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 behaviour even if the pointer is not actually being dereferenced. For example:
/*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;
if (n > 10)
{
}
p = &a[n]; /* 2932 */
p = a + n; /* 2932 */
}
MISRA-C:2004 Rules applicable to message 2932:
| Rule 17.1 (Required) | Pointer arithmetic shall only be applied to pointers that address an array or array element. |
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 |