summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2022-03-27 21:08:36 +0200
committerMark Wielaard <mark@klomp.org>2022-03-30 16:40:05 +0200
commitdec6d82cf2e9c79b9b45a29de5ea2d8f25cc633b (patch)
tree2bc33be084fe10b7b404f9c05800a3bfcc9e92c4 /lib
parent4a22e01277e37540d753e3513c4df3bd2b6e1246 (diff)
downloadelfutils-dec6d82cf2e9c79b9b45a29de5ea2d8f25cc633b.tar.gz
Introduce error_exit as a noreturn variant of error (EXIT_FAILURE, ...)
error (EXIT_FAILURE, ...) should be noreturn but on some systems it isn't. This may cause warnings about code that should not be reachable. So have an explicit error_exit wrapper that is noreturn (because it calls exit explicitly). Use error_exit in all tools under the src directory. https://bugzilla.redhat.com/show_bug.cgi?id=2068692 Signed-off-by: Mark Wielaard <mark@klomp.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/ChangeLog4
-rw-r--r--lib/system.h10
2 files changed, 14 insertions, 0 deletions
diff --git a/lib/ChangeLog b/lib/ChangeLog
index 8f4d4d9f..6b76f647 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,7 @@
+2022-03-27 Mark Wielaard <mark@klomp.org>
+
+ * system.h: define error_exit.
+
2021-02-14 Alexander Miller <alex.miller@gmx.de>
* eu-config.h (used_in_asm): New macro.
diff --git a/lib/system.h b/lib/system.h
index edbc8488..d3f42c91 100644
--- a/lib/system.h
+++ b/lib/system.h
@@ -1,5 +1,6 @@
/* Declarations for common convenience functions.
Copyright (C) 2006-2011 Red Hat, Inc.
+ Copyright (C) 2022 Mark J. Wielaard <mark@klomp.org>
This file is part of elfutils.
This file is free software; you can redistribute it and/or modify
@@ -51,6 +52,15 @@ void error(int status, int errnum, const char *format, ...);
#error "err.h or error.h must be available"
#endif
+/* error (EXIT_FAILURE, ...) should be noreturn but on some systems it
+ isn't. This may cause warnings about code that should not be reachable.
+ So have an explicit error_exit wrapper that is noreturn (because it
+ calls exit explicitly). */
+#define error_exit(errnum,...) do { \
+ error (EXIT_FAILURE,errnum,__VA_ARGS__); \
+ exit (EXIT_FAILURE); \
+ } while (0)
+
#if __BYTE_ORDER == __LITTLE_ENDIAN
# define LE32(n) (n)
# define LE64(n) (n)