From 2d6fb31cd1142befb60cad15ce9da2a7eabb76e2 Mon Sep 17 00:00:00 2001 From: Ondrej Zajicek Date: Tue, 28 May 2024 16:41:24 +0200 Subject: Lib: Use alloc_size() function attribute --- lib/birdlib.h | 3 ++- lib/resource.h | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/birdlib.h b/lib/birdlib.h index b7226411..fac7e4ea 100644 --- a/lib/birdlib.h +++ b/lib/birdlib.h @@ -75,7 +75,8 @@ static inline int u64_cmp(u64 i1, u64 i2) #define NORET __attribute__((noreturn)) #define UNUSED __attribute__((unused)) #define PACKED __attribute__((packed)) -#define NONNULL(...) __attribute__((nonnull((__VA_ARGS__)))) +#define NONNULL(...) __attribute__((nonnull(__VA_ARGS__))) +#define ALLOC_SIZE(...) __attribute__((alloc_size(__VA_ARGS__))) #define STATIC_ASSERT(EXP) _Static_assert(EXP, #EXP) #define STATIC_ASSERT_MSG(EXP,MSG) _Static_assert(EXP, MSG) diff --git a/lib/resource.h b/lib/resource.h index a4e110a5..1e9a7b78 100644 --- a/lib/resource.h +++ b/lib/resource.h @@ -57,9 +57,9 @@ extern pool root_pool; /* Normal memory blocks */ -void *mb_alloc(pool *, unsigned size); -void *mb_allocz(pool *, unsigned size); -void *mb_realloc(void *m, unsigned size); +void *mb_alloc(pool *, unsigned size) ALLOC_SIZE(2); +void *mb_allocz(pool *, unsigned size) ALLOC_SIZE(2); +void *mb_realloc(void *m, unsigned size) ALLOC_SIZE(2); void mb_free(void *); /* Memory pools with linear allocation */ @@ -73,9 +73,9 @@ typedef struct lp_state { } lp_state; linpool *lp_new(pool *); -void *lp_alloc(linpool *, unsigned size); /* Aligned */ -void *lp_allocu(linpool *, unsigned size); /* Unaligned */ -void *lp_allocz(linpool *, unsigned size); /* With clear */ +void *lp_alloc(linpool *, unsigned size) ALLOC_SIZE(2); /* Aligned */ +void *lp_allocu(linpool *, unsigned size) ALLOC_SIZE(2); /* Unaligned */ +void *lp_allocz(linpool *, unsigned size) ALLOC_SIZE(2); /* With clear */ void lp_flush(linpool *); /* Free everything, but leave linpool */ void lp_save(linpool *m, lp_state *p); /* Save state */ void lp_restore(linpool *m, lp_state *p); /* Restore state */ -- cgit v1.2.3