]> diplodocus.org Git - nmh/commitdiff
Add gcc's alloc_size function attribute.
authorRalph Corderoy <ralph@inputplus.co.uk>
Sat, 26 Aug 2017 16:29:08 +0000 (17:29 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Sat, 26 Aug 2017 16:29:08 +0000 (17:29 +0100)
Used for malloc-wrapper, etc.

h/mh.h
h/utils.h
sbr/dtimep.l
uip/dropsbr.c
uip/mkstemp.c

diff --git a/h/mh.h b/h/mh.h
index dda0c3d..e9460db 100644 (file)
--- 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)))
 #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 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
 
 #define NMH_UNUSED(i) i
 #endif
 
index dd3fb43..b745826 100644 (file)
--- 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. */
 #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. */
 
 /* 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. */
 
 /* 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);
 
 /* Duplicate a NUL-terminated string, exit on failure. */
 char *mh_xstrdup(const char *src);
index 238af86..9053708 100644 (file)
@@ -11,6 +11,7 @@
 %a5000
 %{
 #include <h/nmh.h>
 %a5000
 %{
 #include <h/nmh.h>
+#include <h/mh.h>
 #include <h/utils.h>
 #include <h/tws.h>
 
 #include <h/utils.h>
 #include <h/tws.h>
 
index 8f841a1..8cc07cb 100644 (file)
@@ -6,9 +6,8 @@
  */
 
 #include <h/nmh.h>
  */
 
 #include <h/nmh.h>
-#include <h/utils.h>
-
 #include <h/mh.h>
 #include <h/mh.h>
+#include <h/utils.h>
 #include <h/dropsbr.h>
 #include <h/mts.h>
 #include <h/tws.h>
 #include <h/dropsbr.h>
 #include <h/mts.h>
 #include <h/tws.h>
index 7dc8065..b95de57 100644 (file)
@@ -19,8 +19,6 @@
 #include <string.h>
 #include <stdio.h>
 
 #include <string.h>
 #include <stdio.h>
 
-#include <h/utils.h>
-
 #if ! defined HAVE_MKSTEMPS
 #   define HAVE_MKSTEMPS 0
 #endif /* ! HAVE_MKSTEMPS */
 #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 <h/mh.h>
 
 #if NMH
 #include <h/mh.h>
+#include <h/utils.h>
 
 #if HAVE_MKSTEMPS
 #   define MHFIXMSG_SWITCHES \
 
 #if HAVE_MKSTEMPS
 #   define MHFIXMSG_SWITCHES \