Memory alloc size must be a multiple of alignment for aligned_alloc.

This commit is contained in:
Nathan Moinvaziri 2024-01-06 17:15:06 -08:00 committed by Hans Kristian Rosbach
parent 42db8b86a8
commit 2a03576b34

View File

@ -17,6 +17,8 @@
/* Function to allocate 16 or 64-byte aligned memory */ /* Function to allocate 16 or 64-byte aligned memory */
static inline void *zng_alloc(size_t size) { static inline void *zng_alloc(size_t size) {
#ifdef HAVE_ALIGNED_ALLOC #ifdef HAVE_ALIGNED_ALLOC
/* Size must be a multiple of alignment */
size = (size + (64 - 1)) & ~(64 - 1);
return (void *)aligned_alloc(64, size); /* Defined in C11 */ return (void *)aligned_alloc(64, size); /* Defined in C11 */
#elif defined(HAVE_POSIX_MEMALIGN) #elif defined(HAVE_POSIX_MEMALIGN)
void *ptr; void *ptr;