elfutils: fix gcc 8.0+ multistatement macros warning/error

GCC 8.0+ <https://gcc.gnu.org/gcc-8/changes.html> introduces a new
warning about unsafe macros expanding to multiple statements used
as a body of a statement such as if, else, while, switch, or for.

In combination with -Werror this can cause the compilation to fail:

|In file included from xmalloc.c:37:
|xmalloc.c: In function 'xmalloc':
|system.h:39:2: error: macro expands to multiple statements [-Werror=multistatement-macros]
|  fflush(stdout); \
|  ^~~~~~
|xmalloc.c:52:5: note: in expansion of macro 'error'
|     error (EXIT_FAILURE, 0, _("memory exhausted"));
|     ^~~~~
|xmalloc.c:51:3: note: some parts of macro expansion are not guarded by this 'if' clause
|   if (p == NULL)
|   ^~

Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
This commit is contained in:
Christian Lamparter 2018-12-20 18:07:40 +01:00
parent 99c81eab78
commit a8bae35914
1 changed files with 8 additions and 6 deletions

View File

@ -2,7 +2,7 @@ https://sourceware.org/bugzilla/show_bug.cgi?id=21002
--- a/lib/system.h
+++ b/lib/system.h
@@ -30,7 +30,16 @@
@@ -30,7 +30,18 @@
#define LIB_SYSTEM_H 1
#include <errno.h>
@ -13,14 +13,16 @@ https://sourceware.org/bugzilla/show_bug.cgi?id=21002
+#include "err.h"
+#include <stdio.h>
+#define error(status, errno, ...) \
+ do { \
+ fflush(stdout); \
+ warn(__VA_ARGS__); \
+ if (status) exit(status)
+ if (status) exit(status); \
+ } while(0)
+#endif
#include <stddef.h>
#include <stdint.h>
#include <sys/param.h>
@@ -38,6 +47,10 @@
@@ -38,6 +49,10 @@
#include <byteswap.h>
#include <unistd.h>