[previous] MISRA-C:2004  Rule  17.1:  (Required) [next] Pointer arithmetic shall only be applied to pointers that address an array or array element.
Addition and subtraction of integers (including increment and decrement) from pointers that do not point to an array or array element results in undefined behaviour.

Example Code:


/* PRQA S 488,2982,2983,3447 ++ */

#include "misra.h"
#include "m2cmex.h"

extern S16 glob;
extern S16 lot[10];

extern S16 test_1701( void )
{
   S16 *p;

   p = &lot[20];               /* MISRA Violation */

   p = &glob;
   p = p + 10;                 /* MISRA Violation */

   if (glob > 10)
   {
   }

   p = &lot[glob];             /* MISRA Violation */

   return 0;
}


QAC messages that encompass this guideline:

2930 Constant: Computing an invalid pointer value.
2931 Definite: Computing an invalid pointer value.
2932 Apparent: Computing an invalid pointer value.



(c) The Motor Industry Research Association, 2004
QA C Source Code Analyser 8.1.2
MISRA-C:2004 Compliance Module 3.2
© 2013 Programming Research
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index Contents