Skip to content
Permalink
Browse files

libc: minimal: fix realloc function

Excerpt from the manual:

  If ptr is NULL, then the call is equivalent to malloc(size) [...]

Without this commit, such calls end with a BUS FAULT.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
  • Loading branch information...
tgorochowik authored and nashif committed Apr 19, 2019
1 parent 4d9486f commit 1afa9d0e5da6dde74558ed1a9ae35ac6e905bfa6
Showing with 4 additions and 0 deletions.
  1. +4 −0 lib/libc/minimal/source/stdlib/malloc.c
@@ -102,6 +102,10 @@ void *realloc(void *ptr, size_t requested_size)
size_t block_size, total_requested_size;
void *new_ptr;

if (ptr == NULL) {
return malloc(requested_size);
}

if (requested_size == 0) {
return NULL;
}

0 comments on commit 1afa9d0

Please sign in to comment.
You can’t perform that action at this time.