]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
malloc_simple: calloc: don't call memset if malloc failed
authorSimon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Thu, 16 Aug 2018 07:50:32 +0000 (09:50 +0200)
committerTom Rini <trini@konsulko.com>
Fri, 24 Aug 2018 17:20:19 +0000 (13:20 -0400)
malloc_simple() can return 0 if out of memory. Don't call memset
from calloc() in this case but rely on the caller checking
the return value.

Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Reviewed-by: Marek Vasut <marex@denx.de>
common/malloc_simple.c

index c14f8b59c178ee251cc79299f9fcccfbcb1e340a..871b5444bd7d89e48eef21527d172927788d2e40 100644 (file)
@@ -57,7 +57,8 @@ void *calloc(size_t nmemb, size_t elem_size)
        void *ptr;
 
        ptr = malloc(size);
-       memset(ptr, '\0', size);
+       if (ptr)
+               memset(ptr, '\0', size);
 
        return ptr;
 }