From 5e1dbfc49d0f80a247f3c5ba0595e61d231eacad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Petit?= Date: Wed, 4 Mar 2020 15:17:50 +0000 Subject: [PATCH] Fix align_malloc on Linux (#645) posix_memalign requires alignment to be a power of two and a multiple of sizeof(void*). All powers of two greater than sizeof(void*) are multiples of sizeof(void*) so we only need to make sure sizeof(void*) is the minimum value passed to posix_memalign. Fixes #644 Signed-off-by: Kevin Petit --- test_common/harness/alloc.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test_common/harness/alloc.h b/test_common/harness/alloc.h index bcd16d5f..33e6bd81 100644 --- a/test_common/harness/alloc.h +++ b/test_common/harness/alloc.h @@ -40,6 +40,9 @@ static void * align_malloc(size_t size, size_t alignment) if ( ptr ) return ptr; #else + if (alignment < sizeof(void*)) { + alignment = sizeof(void*); + } if (0 == posix_memalign(&ptr, alignment, size)) return ptr; #endif