From ad51c564c238c93d765ce89e0a4042103a2f9db2 Mon Sep 17 00:00:00 2001 From: Will Sackfield Date: Tue, 2 Mar 2021 09:31:25 +0000 Subject: [PATCH 1/2] Ensure aligned_alloc is in 32 byte chunks * The C++ standard does not define what happens if the size is not a multiple of the integral * In macOS Big Sur this results in a NULL output * This makes it impossible to use ffts_init_1d_real on this platform due to the size passed never being an integral of 32 --- src/ffts_internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ffts_internal.h b/src/ffts_internal.h index b74ae348858..06b4405743b 100644 --- a/src/ffts_internal.h +++ b/src/ffts_internal.h @@ -209,7 +209,7 @@ ffts_aligned_malloc(size_t size) /* various ways to allocate aligned memory in order of preferance */ #if defined(HAVE_ALIGNED_ALLOC) - p = aligned_alloc(32, size); + p = aligned_alloc(32, size + (size % 32)); #elif defined(__ICC) || defined(__INTEL_COMPILER) || defined(HAVE__MM_MALLOC) p = (void*) _mm_malloc(size, 32); #elif defined(HAVE_POSIX_MEMALIGN) From 801390067c237939a757211a9499bb8fa0fa84cc Mon Sep 17 00:00:00 2001 From: Will Sackfield Date: Thu, 11 Mar 2021 17:47:33 +0000 Subject: [PATCH 2/2] Fix size not being integral of 32 * Previous solution did not give multiples of 32 --- src/ffts_internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ffts_internal.h b/src/ffts_internal.h index 06b4405743b..e2d4a03b562 100644 --- a/src/ffts_internal.h +++ b/src/ffts_internal.h @@ -209,7 +209,7 @@ ffts_aligned_malloc(size_t size) /* various ways to allocate aligned memory in order of preferance */ #if defined(HAVE_ALIGNED_ALLOC) - p = aligned_alloc(32, size + (size % 32)); + p = aligned_alloc(32, ((size + 32 - 1) / 32) * 32); #elif defined(__ICC) || defined(__INTEL_COMPILER) || defined(HAVE__MM_MALLOC) p = (void*) _mm_malloc(size, 32); #elif defined(HAVE_POSIX_MEMALIGN)