[previous] 2772 [next] Apparent: These pointers address different objects.
Pointers

An apparent condition has been detected. Examination of the context indicates that an operation is being performed which will sometimes compare or subtract the value of two pointers which address different objects.

Behavior is undefined if an attempt is made to subtract pointers which do not address elements of the same array or to compare (with a relational operator) pointers which do not point to the same struct, union or array.

For example, in the code below, the pointer p1 will always address buf1, but p2 will sometimes ad dress buf1 and sometimes buf2, depending on the value of the function parameter n.

For Example:

/*PRQA S 488,490,2017,2983,2991,2995,3120,3132,3199,3203,3227,3355,3358,3408,3447 ++*/

extern int buf1[10];
extern int buf2[10];

extern void f2772(int n)
{
    int * p1;
    int * p2;
    long  d;
    
    p1 = buf1;
    p2 = &buf1[5];

    if (n > 0)
    {
        p2 = buf2;
    }

    d = p2 - p1;         /* 2772 */
    
    if (p2 > p1)         /* 2772 */
    {
    }
}

See also:

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