Skip to content

Commit 5050b63

Browse files
committedApr 19, 2024
define MI_MAX_ALLOC_SIZE as PTRDIFF_MAX (related to #877)
1 parent 06b510c commit 5050b63

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed
 

‎include/mimalloc/types.h

+2
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ typedef int32_t mi_ssize_t;
195195
// Alignments over MI_BLOCK_ALIGNMENT_MAX are allocated in dedicated huge page segments
196196
#define MI_BLOCK_ALIGNMENT_MAX (MI_SEGMENT_SIZE >> 1)
197197

198+
// we never allocate more than PTRDIFF_MAX (see also <https://sourceware.org/ml/libc-announce/2019/msg00001.html>)
199+
#define MI_MAX_ALLOC_SIZE PTRDIFF_MAX
198200

199201
// ------------------------------------------------------
200202
// Mimalloc pages contain allocated blocks

‎src/page.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ static mi_page_t* mi_find_page(mi_heap_t* heap, size_t size, size_t huge_alignme
857857
// huge allocation?
858858
const size_t req_size = size - MI_PADDING_SIZE; // correct for padding_size in case of an overflow on `size`
859859
if mi_unlikely(req_size > (MI_LARGE_OBJ_SIZE_MAX - MI_PADDING_SIZE) || huge_alignment > 0) {
860-
if mi_unlikely(req_size > PTRDIFF_MAX) { // we don't allocate more than PTRDIFF_MAX (see <https://sourceware.org/ml/libc-announce/2019/msg00001.html>)
860+
if mi_unlikely(req_size > MI_MAX_ALLOC_SIZE) {
861861
_mi_error_message(EOVERFLOW, "allocation request is too large (%zu bytes)\n", req_size);
862862
return NULL;
863863
}

0 commit comments

Comments
 (0)