From c8a4fc6e7ab9ac0e3194b61a966da2df4f050ba0 Mon Sep 17 00:00:00 2001 From: Craig Barnes Date: Sun, 12 Jul 2026 14:33:19 +0100 Subject: xmalloc/xsnprintf: simplify some code with new FATAL_ERROR_ON() macro --- xmalloc.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'xmalloc.c') diff --git a/xmalloc.c b/xmalloc.c index e7693d3a..e60c1c6e 100644 --- a/xmalloc.c +++ b/xmalloc.c @@ -8,19 +8,14 @@ static void * check_alloc(void *alloc) { - if (unlikely(alloc == NULL)) { - FATAL_ERROR(__func__, ENOMEM); - } + FATAL_ERROR_ON(alloc == NULL, ENOMEM); return alloc; } void * xmalloc(size_t size) { - if (unlikely(size == 0)) { - size = 1; - } - return check_alloc(malloc(size)); + return check_alloc(malloc(likely(size) ? size : 1)); } void * @@ -72,9 +67,7 @@ xvasprintf_(char **strp, const char *format, va_list ap) va_list ap2; va_copy(ap2, ap); int n = vsnprintf(NULL, 0, format, ap2); - if (unlikely(n < 0)) { - FATAL_ERROR("vsnprintf", EILSEQ); - } + FATAL_ERROR_ON(n < 0, EILSEQ); va_end(ap2); *strp = xmalloc(n + 1); return vsnprintf(*strp, n + 1, format, ap); -- cgit v1.3