>From 0d9d39c0178bc553cc1987ccf7ab1edd02a0c0c1 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 15 Jul 2016 10:35:22 +0200 Subject: [PATCH] obstack: pacify GCC 6 with -Wnull-dereference Problem reported by Assaf Gordon in: http://lists.gnu.org/archive/html/bug-gnulib/2016-07/msg00028.html * lib/obstack.c, lib/obstack.h (obstack_alloc_failed_handler): Declare with __attribute_noreturn__. * lib/obstack.h (__attribute_noreturn__): New macro. --- ChangeLog | 9 +++++++++ lib/obstack.c | 3 ++- lib/obstack.h | 11 ++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 848da1b..2414e8e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2016-07-15 Paul Eggert + + obstack: pacify GCC 6 with -Wnull-dereference + Problem reported by Assaf Gordon in: + http://lists.gnu.org/archive/html/bug-gnulib/2016-07/msg00028.html + * lib/obstack.c, lib/obstack.h (obstack_alloc_failed_handler): + Declare with __attribute_noreturn__. + * lib/obstack.h (__attribute_noreturn__): New macro. + 2016-07-13 Eric Blake doc: mention glibc, OS X, Cygwin [S]SIZE_MAX buglet diff --git a/lib/obstack.c b/lib/obstack.c index 5ce256a..f0da2f7 100644 --- a/lib/obstack.c +++ b/lib/obstack.c @@ -348,6 +348,7 @@ print_and_abort (void) abort gracefully or use longjump - but shouldn't return. This variable by default points to the internal function 'print_and_abort'. */ -void (*obstack_alloc_failed_handler) (void) = print_and_abort; +__attribute_noreturn__ void (*obstack_alloc_failed_handler) (void) + = print_and_abort; # endif /* !_OBSTACK_NO_ERROR_HANDLER */ #endif /* !_OBSTACK_ELIDE_CODE */ diff --git a/lib/obstack.h b/lib/obstack.h index 67623ad..e81c907 100644 --- a/lib/obstack.h +++ b/lib/obstack.h @@ -145,6 +145,15 @@ # define __attribute_pure__ _GL_ATTRIBUTE_PURE #endif +/* Not the same as _Noreturn, since it also works with function pointers. */ +#ifndef __attribute_noreturn__ +# if 2 < __GNUC__ + (8 <= __GNUC_MINOR__) || 0x5110 <= __SUNPRO_C +# define __attribute_noreturn__ __attribute__ ((__noreturn__)) +# else +# define __attribute_noreturn__ +# endif +#endif + #ifdef __cplusplus extern "C" { #endif @@ -212,7 +221,7 @@ extern _OBSTACK_SIZE_T _obstack_memory_used (struct obstack *) more memory. This can be set to a user defined function which should either abort gracefully or use longjump - but shouldn't return. The default action is to print a message and abort. */ -extern void (*obstack_alloc_failed_handler) (void); +extern __attribute_noreturn__ void (*obstack_alloc_failed_handler) (void); /* Exit value used when 'print_and_abort' is used. */ extern int obstack_exit_failure; -- 2.5.5