From: Alejandro Colomar Date: Sat, 29 Jun 2024 16:43:47 +0000 (+0200) Subject: lib/: Use [[gnu::alloc_size(...)]] on allocation functions X-Git-Tag: 4.17.0-rc1~174 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ba3a51e90f8f91733581d884d4fddbd4d2248db6;p=thirdparty%2Fshadow.git lib/: Use [[gnu::alloc_size(...)]] on allocation functions Suggested-by: Martin Uecker Signed-off-by: Alejandro Colomar --- diff --git a/lib/alloc/malloc.h b/lib/alloc/malloc.h index 214782551..338d4c096 100644 --- a/lib/alloc/malloc.h +++ b/lib/alloc/malloc.h @@ -19,6 +19,7 @@ ) +ATTR_ALLOC_SIZE(1, 2) ATTR_MALLOC(free) inline void *mallocarray(size_t nmemb, size_t size); diff --git a/lib/alloc/reallocf.h b/lib/alloc/reallocf.h index cb90fb3fa..7b0f36a84 100644 --- a/lib/alloc/reallocf.h +++ b/lib/alloc/reallocf.h @@ -20,6 +20,7 @@ ) +ATTR_ALLOC_SIZE(2, 3) ATTR_MALLOC(free) inline void *reallocarrayf(void *p, size_t nmemb, size_t size); diff --git a/lib/alloc/x/xcalloc.h b/lib/alloc/x/xcalloc.h index 04cf1ad43..b4785ec25 100644 --- a/lib/alloc/x/xcalloc.h +++ b/lib/alloc/x/xcalloc.h @@ -20,6 +20,7 @@ ) +ATTR_ALLOC_SIZE(1, 2) ATTR_MALLOC(free) void *xcalloc(size_t nmemb, size_t size); diff --git a/lib/alloc/x/xmalloc.h b/lib/alloc/x/xmalloc.h index 02fde6629..1520b7fd8 100644 --- a/lib/alloc/x/xmalloc.h +++ b/lib/alloc/x/xmalloc.h @@ -20,6 +20,7 @@ ) +ATTR_ALLOC_SIZE(1, 2) ATTR_MALLOC(free) inline void *xmallocarray(size_t nmemb, size_t size); diff --git a/lib/alloc/x/xrealloc.h b/lib/alloc/x/xrealloc.h index fa2d6f1fe..ef6749671 100644 --- a/lib/alloc/x/xrealloc.h +++ b/lib/alloc/x/xrealloc.h @@ -23,6 +23,7 @@ ) +ATTR_ALLOC_SIZE(2, 3) ATTR_MALLOC(free) void *xreallocarray(void *p, size_t nmemb, size_t size); diff --git a/lib/attr.h b/lib/attr.h index 3835848dd..44177bfff 100644 --- a/lib/attr.h +++ b/lib/attr.h @@ -10,11 +10,13 @@ # define NORETURN __attribute__((__noreturn__)) # define format_attr(type, fmt, va) __attribute__((format(type, fmt, va))) # define ATTR_ACCESS(...) __attribute__((access(__VA_ARGS__))) +# define ATTR_ALLOC_SIZE(...) __attribute__((alloc_size(__VA_ARGS__))) #else # define MAYBE_UNUSED # define NORETURN # define format_attr(type, fmt, va) # define ATTR_ACCESS(...) +# define ATTR_ALLOC_SIZE(...) #endif #if (__GNUC__ >= 11) && !defined(__clang__)