From 0aec6d930277a2a459cb8889b1dc1c60dd13020a Mon Sep 17 00:00:00 2001 From: daan Date: Sat, 7 Sep 2019 12:01:54 -0700 Subject: [PATCH] don't align to sizes greater than than the allocation size --- src/alloc-aligned.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/alloc-aligned.c b/src/alloc-aligned.c index 7caf0dbc..cf89e274 100644 --- a/src/alloc-aligned.c +++ b/src/alloc-aligned.c @@ -18,8 +18,9 @@ static void* mi_heap_malloc_zero_aligned_at(mi_heap_t* heap, size_t size, size_t // note: we don't require `size > offset`, we just guarantee that // the address at offset is aligned regardless of the allocated size. mi_assert(alignment > 0 && alignment % sizeof(uintptr_t) == 0); - if (alignment <= sizeof(uintptr_t)) return _mi_heap_malloc_zero(heap,size,zero); if (mi_unlikely(size > PTRDIFF_MAX)) return NULL; // we don't allocate more than PTRDIFF_MAX (see ) + // note: we require that alignment is smaller than `size` + if (mi_unlikely(alignment <= sizeof(uintptr_t) || alignment >= size)) return _mi_heap_malloc_zero(heap,size,zero); // try if there is a current small block with just the right alignment if (size <= MI_SMALL_SIZE_MAX) {