[U-Boot] [PATCH 5/5] malloc_simple: calloc: don't call memset if malloc failed

Simon Goldschmidt simon.k.r.goldschmidt at gmail.com
Sun Aug 5 19:35:00 UTC 2018


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 at gmail.com>
---

 common/malloc_simple.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/common/malloc_simple.c b/common/malloc_simple.c
index c14f8b59c1..871b5444bd 100644
--- a/common/malloc_simple.c
+++ b/common/malloc_simple.c
@@ -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;
 }
-- 
2.17.1



More information about the U-Boot mailing list