From 36826a96c9af9611efea6c02d51e02af3dea96a6 Mon Sep 17 00:00:00 2001 From: daan Date: Thu, 27 Jun 2019 13:29:00 -0700 Subject: [PATCH] add power-of-two check to posix_memalign, pr #56 --- src/alloc-override.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/alloc-override.c b/src/alloc-override.c index e06a3e6e..068b1fb3 100644 --- a/src/alloc-override.c +++ b/src/alloc-override.c @@ -136,6 +136,7 @@ int posix_memalign(void** p, size_t alignment, size_t size) { // The spec also dictates we should not modify `*p` on an error. (issue#27) // if (alignment % sizeof(void*) != 0) return EINVAL; // no `p==NULL` check as it is declared as non-null + if ((alignment & (~alignment + 1)) != alignment) return EINVAL; // not a power of 2 void* q = mi_malloc_aligned(size, alignment); if (q==NULL && size != 0) return ENOMEM; *p = q;