mpl: fix parameter requirements to MPM_aligned_alloc

aligned_alloc requires the size to be multiples of alignment. We
add a round up for the size parameter. The posix_memalign requires
the alignment to be multiples of sizeof(void *), adding an assertion
to check.
Esse commit está contido em:
Yanfei Guo
2024-10-14 16:11:02 -05:00
commit 341542db7d
+4 -1
Ver Arquivo
@@ -317,11 +317,14 @@ MPL_STATIC_INLINE_PREFIX void *MPL_aligned_alloc(size_t alignment, size_t size,
MPL_memory_class class)
{
#if defined (MPL_HAVE_ALIGNED_ALLOC)
return aligned_alloc(alignment, size);
/* aligned_alloc requires size to be multiples of alignment, we round it up here */
return aligned_alloc(alignment, MPL_ROUND_UP_ALIGN(size, alignment));
#elif defined (MPL_HAVE_POSIX_MEMALIGN)
void *ptr;
int ret;
/* posix_memalign requires alignment to be multiples of sizeof(void *) */
assert(alignment % sizeof(void *) == 0);
ret = posix_memalign(&ptr, alignment, size);
if (ret != 0)
return NULL;