From 93fb4072e860a7a4e5f89b889fc8dfeb20556c11 Mon Sep 17 00:00:00 2001 From: Roland Hieber Date: Mon, 7 Jan 2019 12:07:33 +0100 Subject: libdt: xzalloc: die on failure Behave like the well-known kernel variant, so existing code that doesn't check xzallocs return value can be ported easier. Signed-off-by: Roland Hieber --- src/dt/common.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/dt/common.h b/src/dt/common.h index 6633be6..cbe17ce 100644 --- a/src/dt/common.h +++ b/src/dt/common.h @@ -85,7 +85,15 @@ int dev_printf(int level, const struct device_d *dev, const char *format, ...) static inline void *xzalloc(size_t size) { - return calloc(1, size); + void * buf = calloc(1, size); + if (!buf || errno == ENOMEM) { + /* although the glibc variant of calloc sets errno, not all + * variants do, but should still return NULL. */ + errno = ENOMEM; + perror("xzalloc"); + exit(1); + } + return buf; } static inline void *xmalloc(size_t size) -- cgit v1.2.3