From 3d84cd8f13d32eaee32b7e1e27c707682d80693e Mon Sep 17 00:00:00 2001 From: Martin Uecker Date: Mon, 2 Sep 2024 22:25:50 +0200 Subject: [PATCH] add alloc_size to xmalloc --- src/misc/misc.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/misc/misc.h b/src/misc/misc.h index 0917d4bbc..7b7e397c3 100644 --- a/src/misc/misc.h +++ b/src/misc/misc.h @@ -32,7 +32,15 @@ #include "misc/cppwrap.h" -extern void* xmalloc(size_t s); +#ifndef alloc_size +#ifndef __clang__ +#define alloc_size(x) [[gnu::alloc_size(x)]] +#else +#define alloc_size(x) +#endif +#endif + +extern void* xmalloc(size_t s) alloc_size(1); extern void xfree(const void*); extern void warn_nonnull_ptr(void*);