From: Paul Eggert Date: Fri, 4 May 2018 00:38:50 +0000 (-0700) Subject: maint: port more modules to GCC 8 X-Git-Tag: v1.0~5669 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=72333a9c6955aa7ca938dbb5295b78e906c89f07;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 712f62b53c..33365241ce 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2018-05-03 Paul Eggert + + 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 Simplify code. Drop support for Borland C++ on Windows. diff --git a/lib/dfa.h b/lib/dfa.h index 4cf033176a..fea815d244 100644 --- a/lib/dfa.h +++ b/lib/dfa.h @@ -22,12 +22,6 @@ #include #include -#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 69aeb8682d..8b5111168d 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 9ef4c237a3..648830d2ee 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 7e4dac1347..cac872f295 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 15afafc66f..27164ef413 100644 --- a/lib/pagealign_alloc.h +++ b/lib/pagealign_alloc.h @@ -20,12 +20,6 @@ # include -#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 a54bf6ceec..1454faab2f 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 ce28a2accc..9ea339453f 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 2a51b840db..c419a2de6c 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 0a4420d3bc..54b0967f15 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 de65f6b82e..736e421016 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