From: Ralph Corderoy Date: Sat, 26 Aug 2017 17:15:21 +0000 (+0100) Subject: Add gcc's malloc function attribute. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/532fff590b4cfbfbd0633d6b58ca1ab0fec2777d?ds=inline;hp=48a82e75469e3bea1eaa88b7fbd4d28a3f275af2 Add gcc's malloc function attribute. Mark wrappers for malloc(3), strdup(3), etc. --- diff --git a/h/mh.h b/h/mh.h index 2a4ce617..3ee706b3 100644 --- a/h/mh.h +++ b/h/mh.h @@ -38,6 +38,7 @@ typedef unsigned char boolean; /* not int so we can pack in a structure */ #define ALLOC_SIZE(n) __attribute__((alloc_size(n))) #define ALLOC_SIZE2(m, n) __attribute__((alloc_size(m, n))) #define CONST __attribute__((const)) +#define MALLOC __attribute__((malloc)) #define NMH_UNUSED(i) (void) i #else #define NORETURN @@ -45,6 +46,7 @@ typedef unsigned char boolean; /* not int so we can pack in a structure */ #define ALLOC_SIZE(n) #define ALLOC_SIZE2(m, n) #define CONST +#define MALLOC #define NMH_UNUSED(i) i #endif diff --git a/h/utils.h b/h/utils.h index b7458268..f8b21985 100644 --- a/h/utils.h +++ b/h/utils.h @@ -11,16 +11,16 @@ extern const char plurals[]; #define PLURALS(n) (plurals + ((n) == 1)) /* Call malloc(3), exiting on NULL return. */ -void *mh_xmalloc(size_t size) ALLOC_SIZE(1); +void *mh_xmalloc(size_t size) MALLOC ALLOC_SIZE(1); /* Call realloc(3), exiting on NULL return. */ 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) ALLOC_SIZE2(1, 2); +void *mh_xcalloc(size_t nelem, size_t elsize) MALLOC ALLOC_SIZE2(1, 2); /* Duplicate a NUL-terminated string, exit on failure. */ -char *mh_xstrdup(const char *src); +char *mh_xstrdup(const char *src) MALLOC; /* Call free(3), if ptr isn't NULL. */ void mh_xfree(void *ptr); @@ -35,8 +35,8 @@ void mh_xfree(void *ptr); #define ZERO(p) memset((p), 0, sizeof *(p)) char *pwd(void); -char *add(const char *, char *); -char *addlist(char *, const char *); +char *add(const char *, char *) MALLOC; +char *addlist(char *, const char *) MALLOC; int folder_exists(const char *); void create_folder(char *, int, void (*)(int)); int num_digits(int);