From b241910810ccfd7c4293afe5f74a48d92a33a88d Mon Sep 17 00:00:00 2001 From: daan Date: Sat, 7 Sep 2019 11:52:21 -0700 Subject: [PATCH] don't allocate more than PTRDIFF_MAX on aligned allocations --- 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 c8c19855..7caf0dbc 100644 --- a/src/alloc-aligned.c +++ b/src/alloc-aligned.c @@ -19,7 +19,7 @@ static void* mi_heap_malloc_zero_aligned_at(mi_heap_t* heap, size_t size, size_t // 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 (size >= (SIZE_MAX - alignment)) return NULL; // overflow + if (mi_unlikely(size > PTRDIFF_MAX)) return NULL; // we don't allocate more than PTRDIFF_MAX (see ) // try if there is a current small block with just the right alignment if (size <= MI_SMALL_SIZE_MAX) {