From c24f2d44a17550287c3cd5826849c4c77b592d04 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Fri, 3 Aug 2018 05:11:45 +0200 Subject: [PATCH] Code cleanup --- src/lib/stdlib.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/lib/stdlib.c b/src/lib/stdlib.c index dd948bc..c2a3b23 100644 --- a/src/lib/stdlib.c +++ b/src/lib/stdlib.c @@ -140,28 +140,25 @@ void * malloc(size_t size) - (intptr_t)sizeof(*a) - (intptr_t)a->size) { - b = (Alloc*)((char*)a + sizeof(*a) + a->size); - b->size = size; + b = (Alloc *)((char *)a + sizeof(*a) + a->size); a->next->prev = b; break; } if(b == NULL) /* increase process size to allocate memory */ - { if((b = sbrk(inc)) == (void *)-1) return NULL; - b->size = size; - } + b->size = size; b->prev = a; b->next = a->next; a->next = b; - return (char *)b + sizeof(*b); + return b + 1; } /* realloc */ void * realloc(void * ptr, size_t size) { - Alloc * a = (Alloc*)((char*)ptr - sizeof(*a)); + Alloc * a = (Alloc *)((char *)ptr - sizeof(*a)); void * p; if(ptr == NULL) @@ -169,7 +166,7 @@ void * realloc(void * ptr, size_t size) if(size == a->size) return ptr; size = (size | 0xf) + 1; /* round up to 64 bits */ - if(size < a->size || (a->next != NULL && (char*)a->next - (char*)a + if(size < a->size || (a->next != NULL && (char *)a->next - (char *)a - sizeof(*a) >= size)) { a->size = size;