Developer Guide and Reference

Contents

Checking Bounds

The pointer checker is not supported on
macOS*
systems.
The pointer checker checks indirect accesses through pointers for accesses that are out of bounds.

Checking Bounds on Read/Write Operations

To check the bounds of pointers, compile your module with
[Q]check-pointers
compiler option, specifying the
rw
argument.
You can also check bounds by specifying the
write
argument. This also checks the bounds of pointers, but only for pointer write operations.
Consider the case where you create an array with ten elements using the
malloc()
function and then you write a character to each array element:
Example: Writing to Each Array Element
char *buf = malloc(10); for (int i=0; i<=10; i++) { buf[i] = ‘A’ + i; }
The array has ten elements, but the loop iterates eleven times. On the eleventh iteration, the function writes a character to the eleventh element of the array, which is outside of the allocated memory. Regardless of whether you specify bounds checking for read and write operations or only write operations, the pointer checker will report an out-of-bounds error. Even in the case of a statically allocated buffer, the pointer checker will still report an error. Consider this case:
Example: Out-of-bounds Error with a Statically Allocated Buffer
fprintf(stderr, "buf[%d]=%d\n",i,buf[i]);
Here, the reference to
buf[i]
is a read (or load) operation. Therefore, an out-of-bounds error will not be reported if you specified pointer checking only for write operations.

Pointer Arithmetic and Pointer Checking

Pointer arithmetic does not affect the pointer checker. A pointer can go out of range as long as the pointer does not make an indirect reference to an out of range address.
In the case where you create an array with 100 elements, the following applies:
Example: Pointer Arithmetic with Pointer Checking
char *p = malloc(100); p += 200; // pointer is out of range, but no error p[-101] = 0; // access is still in range, it is the original p[99] p[0] = 0; // out-of-bounds error occurs here, because it is original p[200]

Product and Performance Information

1

Intel's compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.

Notice revision #20110804