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 <jwerner@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/178725 Reviewed-by: Mike Frysinger <vapier@chromium.org> Reviewed-by: David Hendricks <dhendrix@chromium.org>
This commit is contained in:
parent
f44366993c
commit
3033437e9d
1 changed files with 2 additions and 2 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue