diff --git a/include/mimalloc/types.h b/include/mimalloc/types.h index adfd7838..5d219d68 100644 --- a/include/mimalloc/types.h +++ b/include/mimalloc/types.h @@ -195,6 +195,8 @@ typedef int32_t mi_ssize_t; // Alignments over MI_BLOCK_ALIGNMENT_MAX are allocated in dedicated huge page segments #define MI_BLOCK_ALIGNMENT_MAX (MI_SEGMENT_SIZE >> 1) +// we never allocate more than PTRDIFF_MAX (see also ) +#define MI_MAX_ALLOC_SIZE PTRDIFF_MAX // ------------------------------------------------------ // Mimalloc pages contain allocated blocks diff --git a/src/page.c b/src/page.c index efcd8d91..3b3ba2f9 100644 --- a/src/page.c +++ b/src/page.c @@ -857,7 +857,7 @@ static mi_page_t* mi_find_page(mi_heap_t* heap, size_t size, size_t huge_alignme // huge allocation? const size_t req_size = size - MI_PADDING_SIZE; // correct for padding_size in case of an overflow on `size` if mi_unlikely(req_size > (MI_LARGE_OBJ_SIZE_MAX - MI_PADDING_SIZE) || huge_alignment > 0) { - if mi_unlikely(req_size > PTRDIFF_MAX) { // we don't allocate more than PTRDIFF_MAX (see ) + if mi_unlikely(req_size > MI_MAX_ALLOC_SIZE) { _mi_error_message(EOVERFLOW, "allocation request is too large (%zu bytes)\n", req_size); return NULL; }