mirror of
https://github.com/Zenithsiz/ftmemsim-valgrind.git
synced 2026-02-03 18:13:01 +00:00
47 lines
1.0 KiB
C
47 lines
1.0 KiB
C
|
|
#include <stdlib.h>
|
|
|
|
int main(void)
|
|
{
|
|
int i __attribute__((unused));
|
|
int* y __attribute__((unused));
|
|
int** x = malloc(sizeof(int*) * 100);
|
|
int* x2 = malloc(sizeof(int) * 100);
|
|
void* sink __attribute__((unused));
|
|
x[0] = x2; // this is to check the pointerness is copied across ok
|
|
x[49] = x2; // this is to check the pointerness is copied across ok
|
|
|
|
i = *x[0];
|
|
i = *x[49];
|
|
|
|
x = realloc(x, sizeof(int*)*50); // smaller
|
|
y = x[0]; // ok
|
|
y = x[49]; // ok
|
|
y = x[-1]; // bad
|
|
y = x[50]; // bad
|
|
i = *x[0]; // ok
|
|
i = *x[49]; // ok
|
|
|
|
x = realloc(x, sizeof(int*)*50); // same size
|
|
y = x[0]; // ok
|
|
y = x[49]; // ok
|
|
y = x[-1]; // bad
|
|
y = x[50]; // bad
|
|
i = *x[0]; // ok
|
|
i = *x[49]; // ok
|
|
|
|
x = realloc(x, sizeof(int*)*100); // bigger
|
|
y = x[0]; // ok
|
|
y = x[49]; // ok
|
|
y = x[50]; // ok
|
|
y = x[99]; // ok
|
|
y = x[-1]; // bad
|
|
y = x[100]; // bad
|
|
i = *x[0]; // ok
|
|
i = *x[49]; // ok
|
|
|
|
sink = realloc((void*)0x99, 10); // fails
|
|
|
|
return 0;
|
|
}
|