From 3033437e9d89c6072464860ea50ea27dcb76fe54 Mon Sep 17 00:00:00 2001 From: Julius Werner Date: Wed, 4 Dec 2013 10:49:12 -0800 Subject: [PATCH] libpayload: malloc: Fix xmalloc() for zero byte allocations The C standard considers it legal to return a NULL pointer for zero length memory allocations, and our malloc implementation does in fact make use of that. xmalloc() and xzmalloc() should therefore not consider this case a failure. Also fixed a minor formatting issue. BUG=None TEST=Made sure xmalloc(0) and xmalloc(1000) succeed and xmalloc(0xffffffff) still dies. Change-Id: Ib9b75df9458ce2ba75fd0bc0af9814a3323298eb Signed-off-by: Julius Werner Reviewed-on: https://chromium-review.googlesource.com/178725 Reviewed-by: Mike Frysinger Reviewed-by: David Hendricks --- payloads/libpayload/include/stdlib.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/payloads/libpayload/include/stdlib.h b/payloads/libpayload/include/stdlib.h index 77ba73ef4f..7113b6f7d3 100644 --- a/payloads/libpayload/include/stdlib.h +++ b/payloads/libpayload/include/stdlib.h @@ -153,8 +153,8 @@ static inline void *xmalloc_work(size_t size, const char *file, const char *func, int line) { void *ret = malloc(size); - if (!ret) { - die_work(file, func, line, "Failed to malloc %zd bytes.\n", + if (!ret && size) { + die_work(file, func, line, "Failed to malloc %zu bytes.\n", size); } return ret;