aboutsummaryrefslogtreecommitdiff
path: root/xmalloc.c
diff options
context:
space:
mode:
authorCraig Barnes <craigbarnes@protonmail.com>2026-07-12 13:33:19 +0000
committerDaniel Eklöf <daniel@ekloef.se>2026-07-21 09:00:54 +0000
commitc8a4fc6e7ab9ac0e3194b61a966da2df4f050ba0 (patch)
tree3d59a57c977ac17ef61360d266b020fcf2717763 /xmalloc.c
parentxmalloc: avoid using reallocarray(3) to implement xreallocarray() (diff)
xmalloc/xsnprintf: simplify some code with new FATAL_ERROR_ON() macro
Diffstat (limited to 'xmalloc.c')
-rw-r--r--xmalloc.c13
1 files changed, 3 insertions, 10 deletions
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);