From c066b395274021182a5f0530ccfeb1bcd167d860 Mon Sep 17 00:00:00 2001 From: Ralph Corderoy Date: Sat, 26 Aug 2017 17:29:08 +0100 Subject: [PATCH] Add gcc's alloc_size function attribute. Used for malloc-wrapper, etc. --- h/mh.h | 4 ++++ h/utils.h | 6 +++--- sbr/dtimep.l | 1 + uip/dropsbr.c | 3 +-- uip/mkstemp.c | 3 +-- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/h/mh.h b/h/mh.h index dda0c3d2..e9460db5 100644 --- a/h/mh.h +++ b/h/mh.h @@ -35,10 +35,14 @@ typedef unsigned char boolean; /* not int so we can pack in a structure */ #if __GNUC__ > 2 #define NORETURN __attribute__((__noreturn__)) #define CHECK_PRINTF(fmt, arg) __attribute__((format(printf, fmt, arg))) +#define ALLOC_SIZE(n) __attribute__((alloc_size(n))) +#define ALLOC_SIZE2(m, n) __attribute__((alloc_size(m, n))) #define NMH_UNUSED(i) (void) i #else #define NORETURN #define CHECK_PRINTF(fmt, arg) +#define ALLOC_SIZE(n) +#define ALLOC_SIZE2(m, n) #define NMH_UNUSED(i) i #endif diff --git a/h/utils.h b/h/utils.h index dd3fb431..b7458268 100644 --- a/h/utils.h +++ b/h/utils.h @@ -11,13 +11,13 @@ extern const char plurals[]; #define PLURALS(n) (plurals + ((n) == 1)) /* Call malloc(3), exiting on NULL return. */ -void *mh_xmalloc(size_t size); +void *mh_xmalloc(size_t size) ALLOC_SIZE(1); /* Call realloc(3), exiting on NULL return. */ -void *mh_xrealloc(void *ptr, size_t size); +void *mh_xrealloc(void *ptr, size_t size) ALLOC_SIZE(2); /* Call calloc(3), exiting on NULL return. */ -void *mh_xcalloc(size_t nelem, size_t elsize); +void *mh_xcalloc(size_t nelem, size_t elsize) ALLOC_SIZE2(1, 2); /* Duplicate a NUL-terminated string, exit on failure. */ char *mh_xstrdup(const char *src); diff --git a/sbr/dtimep.l b/sbr/dtimep.l index 238af863..90537088 100644 --- a/sbr/dtimep.l +++ b/sbr/dtimep.l @@ -11,6 +11,7 @@ %a5000 %{ #include +#include #include #include diff --git a/uip/dropsbr.c b/uip/dropsbr.c index 8f841a1e..8cc07cb0 100644 --- a/uip/dropsbr.c +++ b/uip/dropsbr.c @@ -6,9 +6,8 @@ */ #include -#include - #include +#include #include #include #include diff --git a/uip/mkstemp.c b/uip/mkstemp.c index 7dc80656..b95de57f 100644 --- a/uip/mkstemp.c +++ b/uip/mkstemp.c @@ -19,8 +19,6 @@ #include #include -#include - #if ! defined HAVE_MKSTEMPS # define HAVE_MKSTEMPS 0 #endif /* ! HAVE_MKSTEMPS */ @@ -120,6 +118,7 @@ build_template(const char *directory, const char *prefix, const char *suffix) { #if NMH #include +#include #if HAVE_MKSTEMPS # define MHFIXMSG_SWITCHES \ -- 2.56.0