blob: d83827fbd458fc77cdda5620a1b8e69df5fc9ff3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
/* Test that overwrite error detection works reasonably. */
#ifndef GC_DEBUG
# define GC_DEBUG
#endif
#include "gc.h"
#include <stdio.h>
#define COUNT 7000
#define SIZE 40
char * A[COUNT];
char * volatile q;
int main(void)
{
int i;
char *p;
GC_INIT();
for (i = 0; i < COUNT; ++i) {
A[i] = p = (char*)GC_MALLOC(SIZE);
if (i%3000 == 0) {
q = NULL;
GC_gcollect();
} else if (i%5678 == 0 && p != 0) {
/* Write a byte past the end of the allocated object */
/* but not beyond the last word of the object's memory. */
/* A volatile intermediate pointer variable is used to */
/* avoid a compiler complain of out-of-bounds access. */
q = &p[(SIZE + i/2000) /* 42 */];
*q = 42;
}
}
printf("SUCCEEDED\n");
return 0;
}
|