HP aC++/HP C Programmer's Guide (B3901-90036; A.06.26; September 2011)
When +check=all is specified, it enables +check=bounds:array only. To enable
the pointer out-of-bounds check, you must explicitly specify +check=bounds:pointer.
You can combine +check=bounds:[pointer | all] with all other +check options,
except for +check=globals (which would be ignored in this case).
Also see the +check=malloc and the +check=stack options for related runtime
checks for heap and stack objects.
Example:
This example uses +check=bounds:pointer to find a program bug:
$ cat rttest3.c 1 #include <stdio.h>
2 #include <memory.h>
3 #include <stdlib.h>
4 5 int a[10];
6 char b[10];
7 int *ip = &a[0]; // points to global array
8
9 int i;
10
11 void *foo(int n)
12 {
13 return malloc(n * sizeof(int));
14 }
15
16 int main(int argc, char **argv)
17 {
18 int j; // uninitialized variable
19
20 int *lp = (int*)foo(10); // points to heap object
21
22 // out of bound if "a.out 10"
23 if (argc > 1) {
24 i = atoi(argv[1]);
25 }
26
27 memset(b, 'a', i);
28
29 lp[i] = i;
30
31 ip[i+1] = i+1;
32
33 printf("lp[%d]=%d, ip[%d]=%d, ip[j=%d]=%d\n",
34 i, lp[i], i+1, ip[i+1], j, ip[j]);
35
36 return 0;
37 }
Compiling with +check=bounds:pointer:
$ cc +check=bounds:pointer rttest3.c
"rttest3.c", line 34: warning #2549-D: variable "j" is used before its
Runtime Checking Options 93