X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fmalloc%2F__simple_malloc.c;h=61cd9fc491b914e2bd8e9508f82a9a96e2397414;hb=a23baf586a1ca78213d43bce5fee2a30715b473b;hp=49b74c8e9cf44a3c1a1ebb575b87af4cd8fc7eea;hpb=96f2197494791f5884c01b5caa908074cc7e90a6;p=musl diff --git a/src/malloc/__simple_malloc.c b/src/malloc/__simple_malloc.c index 49b74c8e..61cd9fc4 100644 --- a/src/malloc/__simple_malloc.c +++ b/src/malloc/__simple_malloc.c @@ -15,16 +15,16 @@ void *__simple_malloc(size_t n) static int lock; size_t align=1; - if (n < SIZE_MAX - ALIGN) - while (align SIZE_MAX/2) goto toobig; + + while (align SIZE_MAX - brk) goto fail; - base = cur + align-1 & -align; + if (n > SIZE_MAX - PAGE_SIZE - base) goto fail; if (base+n > brk) { new = base+n + PAGE_SIZE-1 & -PAGE_SIZE; if (__brk(new) != new) goto fail; @@ -37,6 +37,7 @@ void *__simple_malloc(size_t n) fail: UNLOCK(&lock); +toobig: errno = ENOMEM; return 0; }