diff --git a/src/malloc/aligned_alloc.c b/src/malloc/aligned_alloc.c index 158dba41238a4fd09cf1c4ac181fa3a92b8f94e3..c63866295339e3373b0bb8978750aa34a6fb4efe 100644 --- a/src/malloc/aligned_alloc.c +++ b/src/malloc/aligned_alloc.c @@ -11,7 +11,7 @@ void *aligned_alloc(size_t align, size_t len) unsigned char *mem, *new, *end; size_t header, footer; - if ((align & -align & -sizeof(void *)) != align) { + if ((align & -align) != align) { errno = EINVAL; return NULL; } diff --git a/src/malloc/posix_memalign.c b/src/malloc/posix_memalign.c index 42cf27405a23d4b50dfb32df6bbba854aa0675ff..ad4d8f473015e378ad1025363cd68507ec539f18 100644 --- a/src/malloc/posix_memalign.c +++ b/src/malloc/posix_memalign.c @@ -3,6 +3,7 @@ int posix_memalign(void **res, size_t align, size_t len) { + if (align < sizeof(void *)) return EINVAL; void *mem = aligned_alloc(align, len); if (!mem) return errno; *res = mem;