-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest011.cc
More file actions
31 lines (28 loc) · 822 Bytes
/
test011.cc
File metadata and controls
31 lines (28 loc) · 822 Bytes
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
#include "dmalloc.hh"
#include <cstdio>
#include <cassert>
#include <cstring>
#include <cstdlib>
// heap_min and heap_max checking, no overlap with other regions.
static int global;
int main() {
for (int i = 0; i != 100; ++i) {
size_t sz = rand() % 100;
char* p = (char*) malloc(sz);
free(p);
}
dmalloc_statistics stat;
dmalloc_get_statistics(&stat);
union {
uintptr_t addr;
int* iptr;
dmalloc_statistics* statptr;
int (*mainptr)();
} x;
x.iptr = &global;
assert(x.addr + sizeof(int) < stat.heap_min || x.addr >= stat.heap_max);
x.statptr = &stat;
assert(x.addr + sizeof(int) < stat.heap_min || x.addr >= stat.heap_max);
x.mainptr = &main;
assert(x.addr + sizeof(int) < stat.heap_min || x.addr >= stat.heap_max);
}