From 3062a58f0ba5fdebc0e06ece63f4ce5b676fcda0 Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Sun, 28 May 2023 12:34:21 +0900 Subject: [PATCH] add the "x" wrapper for reallocarray(3) Signed-off-by: Masatake YAMATO --- include/xalloc.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/xalloc.h b/include/xalloc.h index 1dee5fe9c2..da9245fdba 100644 --- a/include/xalloc.h +++ b/include/xalloc.h @@ -46,6 +46,18 @@ void *xrealloc(void *ptr, const size_t size) return ret; } +static inline +__ul_calloc_size(2, 3) +__ul_returns_nonnull +void *xreallocarray(void *ptr, const size_t nelems, const size_t size) +{ + void *ret = reallocarray(ptr, nelems, size); + + if (!ret && size && nelems) + err(XALLOC_EXIT_CODE, "cannot allocate %zu bytes", size); + return ret; +} + static inline __ul_calloc_size(1, 2) __ul_returns_nonnull -- 2.47.2