]> git.proxmox.com Git - rustc.git/blob - src/jemalloc/test/integration/overflow.c
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / jemalloc / test / integration / overflow.c
1 #include "test/jemalloc_test.h"
2
3 TEST_BEGIN(test_overflow)
4 {
5 unsigned nhchunks;
6 size_t mib[4];
7 size_t sz, miblen, max_size_class;
8 void *p;
9
10 sz = sizeof(unsigned);
11 assert_d_eq(mallctl("arenas.nhchunks", &nhchunks, &sz, NULL, 0), 0,
12 "Unexpected mallctl() error");
13
14 miblen = sizeof(mib) / sizeof(size_t);
15 assert_d_eq(mallctlnametomib("arenas.hchunk.0.size", mib, &miblen), 0,
16 "Unexpected mallctlnametomib() error");
17 mib[2] = nhchunks - 1;
18
19 sz = sizeof(size_t);
20 assert_d_eq(mallctlbymib(mib, miblen, &max_size_class, &sz, NULL, 0), 0,
21 "Unexpected mallctlbymib() error");
22
23 assert_ptr_null(malloc(max_size_class + 1),
24 "Expected OOM due to over-sized allocation request");
25 assert_ptr_null(malloc(SIZE_T_MAX),
26 "Expected OOM due to over-sized allocation request");
27
28 assert_ptr_null(calloc(1, max_size_class + 1),
29 "Expected OOM due to over-sized allocation request");
30 assert_ptr_null(calloc(1, SIZE_T_MAX),
31 "Expected OOM due to over-sized allocation request");
32
33 p = malloc(1);
34 assert_ptr_not_null(p, "Unexpected malloc() OOM");
35 assert_ptr_null(realloc(p, max_size_class + 1),
36 "Expected OOM due to over-sized allocation request");
37 assert_ptr_null(realloc(p, SIZE_T_MAX),
38 "Expected OOM due to over-sized allocation request");
39 free(p);
40 }
41 TEST_END
42
43 int
44 main(void)
45 {
46
47 return (test(
48 test_overflow));
49 }