bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] maint: port more modules to GCC 8


From: Paul Eggert
Subject: [PATCH] maint: port more modules to GCC 8
Date: Thu, 3 May 2018 17:40:30 -0700

* lib/dirname.h (base_name):
* lib/exclude.h (new_exclude):
* lib/xstrndup.h (xstrndup):
Add malloc attribute.
* lib/readutmp.c: Pacify GCC 8 about safe use of strncpy.
* lib/sig-handler.h (get_handler) [SA_SIGINFO]: Simplify.
This pacifies GCC 8.
* m4/gnulib-common.m4 (gl_COMMON_BODY):
Define _GL_ATTRIBUTE_MALLOC here.  All other definitions removed.
---
 ChangeLog             | 13 +++++++++++++
 lib/dfa.h             |  6 ------
 lib/dirname.h         |  2 +-
 lib/eealloc.h         |  6 ------
 lib/exclude.h         |  2 +-
 lib/pagealign_alloc.h |  6 ------
 lib/readutmp.c        |  4 ++++
 lib/sig-handler.h     |  9 +++------
 lib/xalloc.h          |  6 ------
 lib/xstrndup.h        |  2 +-
 m4/gnulib-common.m4   |  9 ++++++++-
 11 files changed, 31 insertions(+), 34 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 712f62b53..33365241c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2018-05-03  Paul Eggert  <address@hidden>
+
+       maint: port more modules to GCC 8
+       * lib/dirname.h (base_name):
+       * lib/exclude.h (new_exclude):
+       * lib/xstrndup.h (xstrndup):
+       Add malloc attribute.
+       * lib/readutmp.c: Pacify GCC 8 about safe use of strncpy.
+       * lib/sig-handler.h (get_handler) [SA_SIGINFO]: Simplify.
+       This pacifies GCC 8.
+       * m4/gnulib-common.m4 (gl_COMMON_BODY):
+       Define _GL_ATTRIBUTE_MALLOC here.  All other definitions removed.
+
 2018-05-03  Bruno Haible  <address@hidden>
 
        Simplify code. Drop support for Borland C++ on Windows.
diff --git a/lib/dfa.h b/lib/dfa.h
index 4cf033176..fea815d24 100644
--- a/lib/dfa.h
+++ b/lib/dfa.h
@@ -22,12 +22,6 @@
 #include <stdbool.h>
 #include <stddef.h>
 
-#if 3 <= __GNUC__
-# define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
-#else
-# define _GL_ATTRIBUTE_MALLOC
-#endif
-
 struct localeinfo; /* See localeinfo.h.  */
 
 /* Element of a list of strings, at least one of which is known to
diff --git a/lib/dirname.h b/lib/dirname.h
index 69aeb8682..8b5111168 100644
--- a/lib/dirname.h
+++ b/lib/dirname.h
@@ -36,7 +36,7 @@ extern "C" {
 #endif
 
 # if GNULIB_DIRNAME
-char *base_name (char const *file);
+char *base_name (char const *file) _GL_ATTRIBUTE_MALLOC;
 char *dir_name (char const *file);
 # endif
 
diff --git a/lib/eealloc.h b/lib/eealloc.h
index 9ef4c237a..648830d2e 100644
--- a/lib/eealloc.h
+++ b/lib/eealloc.h
@@ -39,12 +39,6 @@ _GL_INLINE_HEADER_BEGIN
 # define EEALLOC_INLINE _GL_INLINE
 #endif
 
-#if __GNUC__ >= 3
-# define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
-#else
-# define _GL_ATTRIBUTE_MALLOC
-#endif
-
 #if ! defined __clang__ && \
     (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
 # define _GL_ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args))
diff --git a/lib/exclude.h b/lib/exclude.h
index 7e4dac134..cac872f29 100644
--- a/lib/exclude.h
+++ b/lib/exclude.h
@@ -48,7 +48,7 @@ struct exclude;
 
 bool fnmatch_pattern_has_wildcards (const char *, int) _GL_ATTRIBUTE_PURE;
 
-struct exclude *new_exclude (void);
+struct exclude *new_exclude (void) _GL_ATTRIBUTE_MALLOC;
 void free_exclude (struct exclude *);
 void add_exclude (struct exclude *, char const *, int);
 int add_exclude_file (void (*) (struct exclude *, char const *, int),
diff --git a/lib/pagealign_alloc.h b/lib/pagealign_alloc.h
index 15afafc66..27164ef41 100644
--- a/lib/pagealign_alloc.h
+++ b/lib/pagealign_alloc.h
@@ -20,12 +20,6 @@
 
 # include <stddef.h>
 
-#if __GNUC__ >= 3
-# define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
-#else
-# define _GL_ATTRIBUTE_MALLOC
-#endif
-
 #if ! defined __clang__ && \
     (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
 # define _GL_ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args))
diff --git a/lib/readutmp.c b/lib/readutmp.c
index a54bf6cee..1454faab2 100644
--- a/lib/readutmp.c
+++ b/lib/readutmp.c
@@ -38,6 +38,10 @@
 # include "unlocked-io.h"
 #endif
 
+#if 8 <= __GNUC__
+# pragma GCC diagnostic ignored "-Wsizeof-pointer-memaccess"
+#endif
+
 /* Copy UT->ut_name into storage obtained from malloc.  Then remove any
    trailing spaces from the copy, NUL terminate it, and return the copy.  */
 
diff --git a/lib/sig-handler.h b/lib/sig-handler.h
index ce28a2acc..9ea339453 100644
--- a/lib/sig-handler.h
+++ b/lib/sig-handler.h
@@ -37,15 +37,12 @@ typedef void (*sa_handler_t) (int);
 SIG_HANDLER_INLINE sa_handler_t _GL_ATTRIBUTE_PURE
 get_handler (struct sigaction const *a)
 {
-#ifdef SA_SIGINFO
   /* POSIX says that special values like SIG_IGN can only occur when
      action.sa_flags does not contain SA_SIGINFO.  But in Linux 2.4,
      for example, sa_sigaction and sa_handler are aliases and a signal
-     is ignored if sa_sigaction (after casting) equals SIG_IGN.  So
-     use (and cast) sa_sigaction in that case.  */
-  if (a->sa_flags & SA_SIGINFO)
-    return (sa_handler_t) a->sa_sigaction;
-#endif
+     is ignored if sa_sigaction (after casting) equals SIG_IGN.  In
+     this case, this implementation relies on the fact that the two
+     are aliases, and simply returns sa_handler.  */
   return a->sa_handler;
 }
 
diff --git a/lib/xalloc.h b/lib/xalloc.h
index 2a51b840d..c419a2de6 100644
--- a/lib/xalloc.h
+++ b/lib/xalloc.h
@@ -36,12 +36,6 @@ extern "C" {
 #endif
 
 
-#if __GNUC__ >= 3
-# define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
-#else
-# define _GL_ATTRIBUTE_MALLOC
-#endif
-
 #if ! defined __clang__ && \
     (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
 # define _GL_ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args))
diff --git a/lib/xstrndup.h b/lib/xstrndup.h
index 0a4420d3b..54b0967f1 100644
--- a/lib/xstrndup.h
+++ b/lib/xstrndup.h
@@ -20,4 +20,4 @@
 /* Return a newly allocated copy of at most N bytes of STRING.
    In other words, return a copy of the initial segment of length N of
    STRING.  */
-extern char *xstrndup (const char *string, size_t n);
+extern char *xstrndup (const char *string, size_t n) _GL_ATTRIBUTE_MALLOC;
diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4
index de65f6b82..736e42101 100644
--- a/m4/gnulib-common.m4
+++ b/m4/gnulib-common.m4
@@ -1,4 +1,4 @@
-# gnulib-common.m4 serial 38
+# gnulib-common.m4 serial 39
 dnl Copyright (C) 2007-2018 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -72,6 +72,13 @@ AC_DEFUN([gl_COMMON_BODY], [
 #else
 # define _GL_ATTRIBUTE_CONST /* empty */
 #endif
+
+/* The __malloc__ attribute was added in gcc 3.  */
+#if 3 <= __GNUC__
+# define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
+#else
+# define _GL_ATTRIBUTE_MALLOC /* empty */
+#endif
 ])
   dnl Preparation for running test programs:
   dnl Tell glibc to write diagnostics from -D_FORTIFY_SOURCE=2 to stderr, not
-- 
2.17.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]