diff options
Diffstat (limited to 'src/malloc')
-rw-r--r-- | src/malloc/memalign.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/malloc/memalign.c b/src/malloc/memalign.c index 55fe68e8..cb232476 100644 --- a/src/malloc/memalign.c +++ b/src/malloc/memalign.c @@ -31,8 +31,10 @@ void *__memalign(size_t align, size_t len) if (!(mem = malloc(len + align-1))) return NULL; - header = ((size_t *)mem)[-1]; new = (void *)((uintptr_t)mem + align-1 & -align); + if (new == mem) return mem; + + header = ((size_t *)mem)[-1]; if (!(header & 7)) { ((size_t *)new)[-2] = ((size_t *)mem)[-2] + (new-mem); |