From b28e2bdd93cb14d961aa4ff6e505a8293c2bc059 Mon Sep 17 00:00:00 2001 From: daanx Date: Thu, 2 Jan 2025 15:02:40 -0800 Subject: [PATCH] fix pointer alignment for zero-sized large alignment case --- src/alloc-aligned.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/alloc-aligned.c b/src/alloc-aligned.c index 6b0a33c1..7304eb1d 100644 --- a/src/alloc-aligned.c +++ b/src/alloc-aligned.c @@ -78,7 +78,7 @@ static mi_decl_noinline void* mi_heap_malloc_zero_aligned_at_overalloc(mi_heap_t } else { // otherwise over-allocate - oversize = size + alignment - 1; + oversize = (size < MI_MAX_ALIGN_SIZE ? MI_MAX_ALIGN_SIZE : size) + alignment - 1; // adjust for size <= 16; with size 0 and aligment 64k, we would allocate a 64k block and pointing just beyond that. p = mi_heap_malloc_zero_no_guarded(heap, oversize, zero); if (p == NULL) return NULL; }