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 <kevin.petit@arm.com>
This commit is contained in:
Kévin Petit
2020-03-04 15:17:50 +00:00
committed by GitHub
parent 4ccc214abb
commit 5e1dbfc49d

View File

@@ -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