]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/valgrind/src/valgrind-3.6.0-svn/exp-ptrcheck/tests/realloc.c
update
[l4.git] / l4 / pkg / valgrind / src / valgrind-3.6.0-svn / exp-ptrcheck / tests / realloc.c
1
2 #include <stdlib.h>
3
4 int main(void)
5 {
6    int i __attribute__((unused));
7    int* y __attribute__((unused));
8    int** x  = malloc(sizeof(int*) * 100);
9    int* x2 = malloc(sizeof(int) * 100);
10    void* sink __attribute__((unused));
11    x[0]  = x2;  // this is to check the pointerness is copied across ok
12    x[49] = x2;  // this is to check the pointerness is copied across ok
13    
14    i = *x[0];
15    i = *x[49];
16    
17    x = realloc(x, sizeof(int*)*50);     // smaller
18    y = x[0];   // ok
19    y = x[49];  // ok
20    y = x[-1];  // bad
21    y = x[50];  // bad
22    i = *x[0];  // ok
23    i = *x[49]; // ok
24
25    x = realloc(x, sizeof(int*)*50);     // same size
26    y = x[0];   // ok
27    y = x[49];  // ok
28    y = x[-1];  // bad
29    y = x[50];  // bad
30    i = *x[0];  // ok
31    i = *x[49]; // ok
32
33    x = realloc(x, sizeof(int*)*100);     // bigger
34    y = x[0];   // ok
35    y = x[49];  // ok
36    y = x[50];  // ok
37    y = x[99];  // ok
38    y = x[-1];  // bad
39    y = x[100]; // bad
40    i = *x[0];  // ok
41    i = *x[49]; // ok
42
43    sink = realloc((void*)0x99, 10);    // fails
44
45    return 0;
46 }