mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-07-06 11:34:38 +03:00
restrict max aligment boundary to prevent bug with segment determination (found by Matthew Parkinson).
This commit is contained in:
parent
60790e9013
commit
684c2c82a7
3 changed files with 6 additions and 1 deletions
|
@ -20,6 +20,7 @@ static void* mi_heap_malloc_zero_aligned_at(mi_heap_t* const heap, const size_t
|
|||
mi_assert(alignment > 0);
|
||||
if (mi_unlikely(size > PTRDIFF_MAX)) return NULL; // we don't allocate more than PTRDIFF_MAX (see <https://sourceware.org/ml/libc-announce/2019/msg00001.html>)
|
||||
if (mi_unlikely(alignment==0 || !_mi_is_power_of_two(alignment))) return NULL; // require power-of-two (see <https://en.cppreference.com/w/c/memory/aligned_alloc>)
|
||||
if (mi_unlikely(alignment>MI_ALIGNED_MAX)) return NULL; // we cannot align at a boundary larger than this (or otherwise we cannot find segment headers)
|
||||
const uintptr_t align_mask = alignment-1; // for any x, `(x & align_mask) == (x % alignment)`
|
||||
|
||||
// try if there is a small block available with just the right alignment
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue