Debian Codegraph @

external/bdwgc/tests/smash_test.c

raw
1 /*
2 * Test that overwrite error detection works reasonably.
3 */
4 #define GC_DEBUG
5 #include "gc.h"
6
7 #include <stdio.h>
8
9 #define COUNT 7000
10 #define SIZE 40
11
12 char * A[COUNT];
13
14 int main(void)
15 {
16 int i;
17 char *p;
18
19 GC_INIT();
20
21 for (i = 0; i < COUNT; ++i) {
22 A[i] = p = (char*)GC_MALLOC(SIZE);
23
24 if (i%3000 == 0) GC_gcollect();
25
26 /* out of range access is intentional */
27 #if defined(__GNUC__) && !defined(__clang__)
28 # pragma GCC diagnostic push
29 # pragma GCC diagnostic ignored "-Warray-bounds"
30 # pragma GCC diagnostic ignored "-Wstringop-overflow"
31 #endif
32
33 if (i%5678 == 0 && p != 0) p[SIZE + i/2000] = 42;
34
35 #if defined(__GNUC__) && !defined(__clang__)
36 # pragma GCC diagnostic pop
37 #endif
38 }
39 return 0;
40 }