[tz] [PROPOSED] Port better to GCC 8

Paul Eggert eggert at cs.ucla.edu
Tue May 1 16:43:54 UTC 2018


* private.h (ATTRIBUTE_MALLOC): New macro.  Use this and
related macros starting with GCC 3.0, not GCC 2.96 which was not
an official release.
* zdump.c (xmalloc):
* zic.c (emalloc, ecpyalloc):
Use it to pacify -Wsuggest-attribute=malloc with GCC 8.
---
 private.h | 4 +++-
 zdump.c   | 2 +-
 zic.c     | 4 ++--
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/private.h b/private.h
index 705544e..641f905 100644
--- a/private.h
+++ b/private.h
@@ -342,12 +342,14 @@ typedef unsigned long uintmax_t;
 #define SIZE_MAX ((size_t) -1)
 #endif
 
-#if 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
+#if 3 <= __GNUC__
 # define ATTRIBUTE_CONST __attribute__ ((const))
+# define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
 # define ATTRIBUTE_PURE __attribute__ ((__pure__))
 # define ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
 #else
 # define ATTRIBUTE_CONST /* empty */
+# define ATTRIBUTE_MALLOC /* empty */
 # define ATTRIBUTE_PURE /* empty */
 # define ATTRIBUTE_FORMAT(spec) /* empty */
 #endif
diff --git a/zdump.c b/zdump.c
index 1081648..a4d9108 100644
--- a/zdump.c
+++ b/zdump.c
@@ -136,7 +136,7 @@ sumsize(size_t a, size_t b)
 
 /* Return a pointer to a newly allocated buffer of size SIZE, exiting
    on failure.  SIZE should be nonzero.  */
-static void *
+static void * ATTRIBUTE_MALLOC
 xmalloc(size_t size)
 {
   void *p = malloc(size);
diff --git a/zic.c b/zic.c
index 90ae1f4..31f1092 100644
--- a/zic.c
+++ b/zic.c
@@ -447,7 +447,7 @@ memcheck(void *ptr)
 	return ptr;
 }
 
-static void *
+static void * ATTRIBUTE_MALLOC
 emalloc(size_t size)
 {
   return memcheck(malloc(size));
@@ -459,7 +459,7 @@ erealloc(void *ptr, size_t size)
   return memcheck(realloc(ptr, size));
 }
 
-static char *
+static char * ATTRIBUTE_MALLOC
 ecpyalloc (char const *str)
 {
   return memcheck(strdup(str));
-- 
2.17.0



More information about the tz mailing list