]> diplodocus.org Git - nmh/commitdiff
Add gcc's malloc function attribute.
authorRalph Corderoy <ralph@inputplus.co.uk>
Sat, 26 Aug 2017 17:15:21 +0000 (18:15 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Sat, 26 Aug 2017 17:15:21 +0000 (18:15 +0100)
Mark wrappers for malloc(3), strdup(3), etc.

h/mh.h
h/utils.h

diff --git a/h/mh.h b/h/mh.h
index 2a4ce617a3fd051e9a03942e1a7e44ee765ed04c..3ee706b39dcc7951ab201191010603f73fb38b13 100644 (file)
--- 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 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
 #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 ALLOC_SIZE(n)
 #define ALLOC_SIZE2(m, n)
 #define CONST
+#define MALLOC
 #define NMH_UNUSED(i) i
 #endif
 
 #define NMH_UNUSED(i) i
 #endif
 
index b74582685ac4c87501a61903dc134f6b35bee9c5..f8b2198557ffc59811c9fc37cc9a43fd6cdce9f7 100644 (file)
--- 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. */
 #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. */
 
 /* 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. */
 
 /* 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);
 
 /* 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);
 #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);
 int folder_exists(const char *);
 void create_folder(char *, int, void (*)(int));
 int num_digits(int);