]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/: Use [[gnu::alloc_size(...)]] on allocation functions
authorAlejandro Colomar <alx@kernel.org>
Sat, 29 Jun 2024 16:43:47 +0000 (18:43 +0200)
committerSerge Hallyn <serge@hallyn.com>
Tue, 2 Jul 2024 02:40:11 +0000 (21:40 -0500)
Suggested-by: Martin Uecker <uecker@tugraz.at>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/alloc/malloc.h
lib/alloc/reallocf.h
lib/alloc/x/xcalloc.h
lib/alloc/x/xmalloc.h
lib/alloc/x/xrealloc.h
lib/attr.h

index 21478255116da3a486a521afe24ed182da7efea2..338d4c0960588574f80021af0e8ddae42abc31c1 100644 (file)
@@ -19,6 +19,7 @@
 )
 
 
+ATTR_ALLOC_SIZE(1, 2)
 ATTR_MALLOC(free)
 inline void *mallocarray(size_t nmemb, size_t size);
 
index cb90fb3fa0d1bd92c25e4dcfc262346c80bdbdb1..7b0f36a84e1731e5e1fa24f68792916664ef51d1 100644 (file)
@@ -20,6 +20,7 @@
 )
 
 
+ATTR_ALLOC_SIZE(2, 3)
 ATTR_MALLOC(free)
 inline void *reallocarrayf(void *p, size_t nmemb, size_t size);
 
index 04cf1ad438f803690290147cf28674ca857f09c4..b4785ec25b4de1c117989bd063d94d0989bd4f69 100644 (file)
@@ -20,6 +20,7 @@
 )
 
 
+ATTR_ALLOC_SIZE(1, 2)
 ATTR_MALLOC(free)
 void *xcalloc(size_t nmemb, size_t size);
 
index 02fde662975758c51033e277c4ea4768e689d322..1520b7fd899dd9121dacec7a6d964cf296662fcc 100644 (file)
@@ -20,6 +20,7 @@
 )
 
 
+ATTR_ALLOC_SIZE(1, 2)
 ATTR_MALLOC(free)
 inline void *xmallocarray(size_t nmemb, size_t size);
 
index fa2d6f1fe54394ea55a9268fedc1dffa84846515..ef67496719591c72709987dbb379bc279cc67540 100644 (file)
@@ -23,6 +23,7 @@
 )
 
 
+ATTR_ALLOC_SIZE(2, 3)
 ATTR_MALLOC(free)
 void *xreallocarray(void *p, size_t nmemb, size_t size);
 
index 3835848ddf483eabd4d5c99588506cc7b281ddff..44177bfff45be629a56694b96413ad3dcdd5bf99 100644 (file)
 # 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__)