From 6f28664854190cbe48dc986b236dff72eedfeebc Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Sat, 26 Apr 2025 17:21:40 +1000 Subject: [PATCH] util: move zalloc to util-mem.h zalloc pre-dates util-mem.h but let's move it there, it makes more sense than including util-strings.h. Part-of: --- src/util-mem.h | 18 ++++++++++++++++++ src/util-strings.h | 17 ----------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/util-mem.h b/src/util-mem.h index 7e472464..7c42d5b3 100644 --- a/src/util-mem.h +++ b/src/util-mem.h @@ -26,10 +26,28 @@ #include "config.h" +#include #include #include #include +static inline void * +zalloc(size_t size) +{ + void *p; + + /* We never need to alloc anything more than 1,5 MB so we can assume + * if we ever get above that something's going wrong */ + if (size > 1536 * 1024) + assert(!"bug: internal malloc size limit exceeded"); + + p = calloc(1, size); + if (!p) + abort(); + + return p; +} + /** * Use: _cleanup_(somefunction) struct foo *bar; */ diff --git a/src/util-strings.h b/src/util-strings.h index b3139289..069d554c 100644 --- a/src/util-strings.h +++ b/src/util-strings.h @@ -70,23 +70,6 @@ strneq(const char *str1, const char *str2, int n) return str1 == str2; } -static inline void * -zalloc(size_t size) -{ - void *p; - - /* We never need to alloc anything more than 1,5 MB so we can assume - * if we ever get above that something's going wrong */ - if (size > 1536 * 1024) - assert(!"bug: internal malloc size limit exceeded"); - - p = calloc(1, size); - if (!p) - abort(); - - return p; -} - /** * strdup guaranteed to succeed. If the input string is NULL, the output * string is NULL. If the input string is a string pointer, we strdup or