fix warnings

This commit is contained in:
daanx 2023-05-02 18:31:07 -07:00
parent 8fffc92e15
commit 7897433412
2 changed files with 5 additions and 30 deletions

View file

@ -18,14 +18,13 @@ static void test_reserved(void);
static void negative_stat(void);
static void alloc_huge(void);
static void test_heap_walk(void);
static void test_remap(void);
static void test_remap_realloc(void);
static void test_remap(bool start_remappable);
int main() {
mi_version();
mi_stats_reset();
test_remap_realloc();
test_remap(true);
// detect double frees and heap corruption
// double_free1();
@ -221,12 +220,12 @@ static void test_heap_walk(void) {
}
static void test_remap(void) {
static void test_remap(bool start_remappable) {
const size_t iterN = 100;
const size_t size0 = 64 * 1024 * 1024;
const size_t inc = 1024 * 1024;
size_t size = size0;
uint8_t* p = (uint8_t*)mi_malloc_remappable(size);
uint8_t* p = (uint8_t*)(start_remappable ? mi_malloc_remappable(size) : mi_malloc(size));
memset(p, 1, size);
for (int i = 2; i < iterN; i++) {
p = mi_realloc(p, size + inc);
@ -245,30 +244,6 @@ static void test_remap(void) {
mi_free(p);
}
static void test_remap_realloc(void) {
const size_t iterN = 100;
const size_t size0 = 64 * 1024 * 1024;
const size_t inc = 1024 * 1024;
size_t size = size0;
uint8_t* p = (uint8_t*)mi_malloc(size);
memset(p, 1, size);
for (int i = 2; i < iterN; i++) {
p = mi_realloc(p, size + inc);
memset(p + size, i, inc);
size += inc;
printf("%3d: increased to size %zu\n", i, size);
}
for (int i = 1; i < iterN; i++) {
size_t idx = size0 + ((i - 1) * inc) - 1;
uint8_t v = p[idx];
if (v != i) {
printf("error: corrupted memory in remap_realloc: i=%d, index=0x%zx, value=%u \n", i, idx, v);
abort();
};
}
mi_free(p);
}
// ----------------------------
// bin size experiments