![]() |
![]() |
2951 | ![]() |
||||
![]() | |||||||
| Arrays | |||||||
An expression with negative value is being added or subtracted from a pointer. Dataflow has been unable to determine the dimensions of the object which the pointer may be addressing. Is this intended ? If the original pointer and the resulting pointer do not address elements of the same array or the element one past the end of the array, the result will be invalid. Notice that this message is not generated when subtracting a positive value from a pointer. It is only generated when adding or subtracting an expression with negative value. For example:
/*PRQA S 488,491,492,510,2017,2211,2824,2982,2983,2984,2986,3120,3132,3198,3199,3203,3227,3408,3447,3673,3686 ++*/
void foo(int *p, int n)
{
int r;
if (n < 0)
{
r = p[n]; /* 2951 */
r = *(p + n); /* 2951 */
r = *(p - n); /* 2951 */
}
if (n > 0)
{
r = p[n]; /* */
r = *(p + n); /* */
r = *(p - n); /* */
}
}
No MISRA-C:2004 Rules applicable to message 2951
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 |