Home | History | Annotate | Download | only in tests
      1 
      2 #include <stdlib.h>
      3 
      4 int main(void)
      5 {
      6    int i;
      7    int* y;
      8    int** x  = malloc(sizeof(int*) * 100);
      9    int* x2 = malloc(sizeof(int) * 100);
     10    void* sink;
     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 }
     47