From: Paul Floyd Date: Sat, 6 Sep 2025 18:56:25 +0000 (+0200) Subject: aligned_alloc wrapper: handle size and aligned values of 0 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7a5f3be6915cd28665346b21b07d02b3f1508bdb;p=thirdparty%2Fvalgrind.git aligned_alloc wrapper: handle size and aligned values of 0 --- diff --git a/coregrind/m_replacemalloc/vg_replace_malloc.c b/coregrind/m_replacemalloc/vg_replace_malloc.c index 96edc5bfe..1df4419ca 100644 --- a/coregrind/m_replacemalloc/vg_replace_malloc.c +++ b/coregrind/m_replacemalloc/vg_replace_malloc.c @@ -2299,7 +2299,13 @@ extern int * __error(void) __attribute__((weak)); #define VG_ALIGNED_ALLOC_ALIGN_FACTOR_FOUR 0 #endif -#if defined(MUSL_LIBC) +#if defined(VGO_freebsd) || defined(VGO_solaris) +#define VG_ALIGNED_ALLOC_NO_ALIGN_ZERO 1 +#else +#define VG_ALIGNED_ALLOC_NO_ALIGN_ZERO 0 +#endif + +#if defined(VGO_freebsd) || defined(MUSL_LIBC) #define VG_ALIGNED_ALLOC_NO_SIZE_ZERO 0 #else #define VG_ALIGNED_ALLOC_NO_SIZE_ZERO 1 @@ -2364,8 +2370,9 @@ extern int * __error(void) __attribute__((weak)); VERIFY_ALIGNMENT(&aligned_alloc_info); \ MALLOC_TRACE("aligned_alloc(al %llu, size %llu)", \ (ULong)alignment, (ULong)size ); \ - if ((VG_ALIGNED_ALLOC_NO_SIZE_ZERO && (alignment == 0)) \ - || (VG_ALIGNED_ALLOC_SIZE_MULTIPLE_ALIGN && (size % alignment != 0)) \ + if ((VG_ALIGNED_ALLOC_NO_SIZE_ZERO && (size == 0)) \ + || (VG_ALIGNED_ALLOC_NO_ALIGN_ZERO && (alignment == 0)) \ + || (VG_ALIGNED_ALLOC_SIZE_MULTIPLE_ALIGN && alignment && (size % alignment != 0)) \ || (VG_ALIGNED_ALLOC_ALIGN_POWER_TWO && (alignment & (alignment - 1)) != 0) \ || (VG_ALIGNED_ALLOC_ALIGN_FACTOR_FOUR && (alignment % 4 != 0))) { \ SET_ERRNO_EINVAL; \