/* >>>------------------------------------------------------------ * * File: rule_17.4.c, Module: M2CM-3.2-QAC-8.1.2 * * RULE 17.4 (Required): * Array indexing shall be the only allowed form of pointer * arithmetic. * * Implemented by messages: * 488 Performing pointer arithmetic. * * 489 The integer value 1 is being added or subtracted from a * pointer. * * 491 Array subscripting applied to an object of pointer type. * * 492 Array subscripting applied to a function parameter * declared as a pointer. * * <<<------------------------------------------------------------ */ #include "misra.h" #include "m2cmex.h" static S16 * gpi; static S16 test_1704a( const S16 * pi1, const S16 pi2[] ); extern S16 test_1704( void ) { S16 i; S16 n; S16 buf1[ 10 ] = { 0 }; S16 buf2[ 10 ] = { 0 }; S16 *p; for ( i = 0; i < 10; ++i ) { buf1[i] = i; /* OK */ } p = &buf2[0]; for ( i = 0; i < 10; ++i ) { *p = i; /* MISRA Violation */ ++p; } n = p - &buf2[0]; /* MISRA Violation */ gpi = &s16a; n = n + test_1704a(buf1, buf2); return n; } static S16 test_1704a( const S16 * pi1, const S16 pi2[] ) { S16 r; S16 s; S16 t; r = gpi[3]; /* MISRA Violation */ s = pi1[3]; /* MISRA Violation */ t = pi2[3]; /* OK */ return r + s + t; }