diff --git a/lib/alloc/malloc.h b/lib/alloc/malloc.h index 21478255..338d4c09 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 cb90fb3f..7b0f36a8 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 04cf1ad4..b4785ec2 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 02fde662..1520b7fd 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 fa2d6f1f..ef674967 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 3835848d..44177bff 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__)