add power-of-two check to posix_memalign, pr #56
This commit is contained in:
parent
ec2a8f387b
commit
36826a96c9
@ -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)
|
||||
// <http://man7.org/linux/man-pages/man3/posix_memalign.3.html>
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user