[previous] 2930 [next] Constant: Computing an invalid pointer value.
Arrays

An invalid pointer address is being 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.

For example:


/*PRQA S 488,489,2017,2824,2982,2983,2984,2986,3120,3132,3198,3199,3203,3408,3447,3681,3683 ++*/


extern int a[10];

extern void foo(void)
{
    int *p;
    int  x;
    

    p = &a[-1];                 /* 2930 */
    p = a - 1;                  /* 2930 */

    p = &a[5];                  /*      */
    p = a + 5;                  /*      */

    p = &a[10];                 /*      */
    p = a + 10;                 /*      */

    p = &a[11];                 /* 2930 */
    p = a + 11;                 /* 2930 */
    
    p = &x - 1;                 /* 2930 */
    p = &x;                     /*      */
    p = &x + 1;                 /*      */
    p = &x + 2;                 /* 2930 */

}

See also:

QA·C Source Code Analyser 8.1.2
© 2013 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index Contents