lkml.org 
[lkml]   [2022]   [Mar]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [RFC PATCH v1 5/6] tools/nolibc/stdlib: Implement `malloc()`, `calloc()`, `realloc()` and `free()`
From
On 3/20/22 10:50 PM, Alviro Iskandar Setiawan wrote:
> This better be simplified like this, so only have 1 malloc() call that
> applies to both branches.
>
> void *realloc(void *old_ptr, size_t new_size)
> {
> struct nolibc_heap *heap;
> void *ret;
>
> ret = malloc(new_size);
> if (__builtin_expect(!ret, 0))
> return NULL;
>
> if (!old_ptr)
> return ret;
>
> heap = container_of(old_ptr, struct nolibc_heap, user_p);
> memcpy(ret, heap->user_p, heap->len);
> munmap(heap, heap->len);
> return ret;
> }

That looks better, will take this for the v2. Thanks!

--
Ammar Faizi

\
 
 \ /
  Last update: 2022-03-20 17:10    [W:0.053 / U:0.532 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site