MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / main

Function main

3rd/mimalloc-2.0.9/test/test-wrong.c:33–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31#endif
32
33int main(int argc, char** argv) {
34 int* p = (int*)mi(malloc)(3*sizeof(int));
35
36 int* r = (int*)mi_malloc_aligned(8,16);
37 mi_free(r);
38
39 // illegal byte wise read
40 char* c = (char*)mi(malloc)(3);
41 printf("invalid byte: over: %d, under: %d\n", c[4], c[-1]);
42 mi(free)(c);
43
44 // undefined access
45 int* q = (int*)mi(malloc)(sizeof(int));
46 printf("undefined: %d\n", *q);
47
48 // illegal int read
49 printf("invalid: over: %d, under: %d\n", q[1], q[-1]);
50
51 *q = 42;
52
53 // buffer overflow
54 q[1] = 43;
55
56 // buffer underflow
57 q[-1] = 44;
58
59 mi(free)(q);
60
61 // double free
62 mi(free)(q);
63
64 // use after free
65 printf("use-after-free: %d\n", *q);
66
67 // leak p
68 // mi_free(p)
69 return 0;
70}

Callers

nothing calls this directly

Calls 2

mi_malloc_alignedFunction · 0.85
mi_freeFunction · 0.85

Tested by

no test coverage detected