lib/: Use [[gnu::alloc_size(...)]] on allocation functions

Suggested-by: Martin Uecker <uecker@tugraz.at>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
Alejandro Colomar
2024-06-29 18:43:47 +02:00
committed by Serge Hallyn
parent 5111e5ed1b
commit ba3a51e90f
6 changed files with 7 additions and 0 deletions

View File

@@ -19,6 +19,7 @@
)
ATTR_ALLOC_SIZE(1, 2)
ATTR_MALLOC(free)
inline void *mallocarray(size_t nmemb, size_t size);

View File

@@ -20,6 +20,7 @@
)
ATTR_ALLOC_SIZE(2, 3)
ATTR_MALLOC(free)
inline void *reallocarrayf(void *p, size_t nmemb, size_t size);

View File

@@ -20,6 +20,7 @@
)
ATTR_ALLOC_SIZE(1, 2)
ATTR_MALLOC(free)
void *xcalloc(size_t nmemb, size_t size);

View File

@@ -20,6 +20,7 @@
)
ATTR_ALLOC_SIZE(1, 2)
ATTR_MALLOC(free)
inline void *xmallocarray(size_t nmemb, size_t size);

View File

@@ -23,6 +23,7 @@
)
ATTR_ALLOC_SIZE(2, 3)
ATTR_MALLOC(free)
void *xreallocarray(void *p, size_t nmemb, size_t size);

View File

@@ -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__)