Insure++ Reference - EXPR_UNRELATED_PTRCMP
This error is generated whenever an expression tries to compare
pointers that do not point into the same memory block. This only applies
to the operators >, >=, <, and <=. The operators == and !=
are exempt from this case.
The ANSI C-language specification declares this construct undefined
except in the special case where a pointer points to an object one past
the end of a block.
The following code illustrates the problem by comparing pointers to
two data objects.
1: /*
2: * File: expucmp.c
3: */
4: #include <stdlib.h>
5:
6: main()
7: {
8: char a[10], *b;
9:
10: b = (char *)malloc(10);
11:
12: if(a > b) a[0] = 'x';
13: else a[0] = 'y';
14: return (0);
15: }
Note that the error in this code is not that the two objects
a and b are of different data
types (array vs. dynamic memory block), but that the comparison in line
12 attempts to compare pointers which do not point into the same memory
block. According to the ANSI specification, this is an undefined
operation.
1. [expucmp.c:12] **EXPR_UNRELATED_PTRCMP**
>> if(a > b) a[0] = 'x';
2. Expression compares unrelated pointers: a > b
Left hand side : 0xf7fffb8c
3. In block : 0xf7fffb8c thru 0xf7fffb95 (10 bytes)
a, declared at expucmp.c, 8
Right hand side : 0x00013870
In block : 0x00013870 thru 0x00013879 (10 bytes)
block allocated at:
malloc() (interface)
main() expucmp.c, 10
4. Stack trace where the error occurred:
main() expucmp.c, 12
- Source line at which the problem was detected.
- Description of the problem and the expression that is in error.
- Description of the two pointers involved in the comparison.
For each pointer, the associated block of memory is shown
together with its size and the line number at which it was
declared or allocated.
- Stack trace showing the function call sequence leading to the
error.
While this construct is technically undefined according to the ANSI C
specification, it is supported on many machines and its use is fairly
common practice. If your application genuinely needs to use this construct,
you can suppress error messages by adding the option
insure++.suppress EXPR_UNRELATED_PTRCMP
to the .psrc file.
EXPR_UNINIT_PTR
EXPR_UNRELATED_PTRDIFF
|