Hi Dmitry,

On Thu, 2025-04-03 at 19:28 +0300, Dmitry V. Levin wrote:
> I've accidentally noticed that this hunk was not correct back in 2017
> because "#if HAVE_CONFIG_H" is not the same as "#ifdef HAVE_CONFIG_H".
> This was not problematic for elfutils itself because HAVE_CONFIG_H is
> always defined.
> 
> Note, however, that as a side effect of commit 76c84c137a82 ("handle libc
> implementations which do not provide `error.h`") "system.h" now includes
> <config.h> unconditionally, essentially reintroducing the original issue
> of including config.h twice for all files that include both <config.h>
> and "system.h".

So to be (pedantically) correct should we include the attached?

Thanks,

Mark
From f14c00adb24bf15059821ca972e5d20a58b893fa Mon Sep 17 00:00:00 2001
From: Mark Wielaard <m...@klomp.org>
Date: Fri, 4 Apr 2025 13:50:04 +0200
Subject: [PATCH] lib: Prevent double inclusion of config.h through system.h

Files that include both <config.h> and "system.h" might include
config.h twice. Prevent that by adding a guard check in system.h
before including config.h.

       * lib/error.h: Check HAVE_CONFIG_H before including config.h.
       * lib/system.h: Check both HAVE_CONFIG_H and whether
       EU_CONFIG_H is defined before including config.h.

Signed-off-by: Mark Wielaard <m...@klomp.org>
---
 lib/error.c  | 4 +++-
 lib/system.h | 7 ++++++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/lib/error.c b/lib/error.c
index 5186fc15e9d5..75c9eafb58ba 100644
--- a/lib/error.c
+++ b/lib/error.c
@@ -26,7 +26,9 @@
    the GNU Lesser General Public License along with this program.  If
    not, see <http://www.gnu.org/licenses/>.  */
 
-#include <config.h>
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
 
 #if !defined(HAVE_ERROR_H) && defined(HAVE_ERR_H)
 #include <errno.h>
diff --git a/lib/system.h b/lib/system.h
index 0698e5ffbe2f..c17e2aa0fea1 100644
--- a/lib/system.h
+++ b/lib/system.h
@@ -31,7 +31,12 @@
 #ifndef LIB_SYSTEM_H
 #define LIB_SYSTEM_H	1
 
-#include <config.h>
+/* Prevent double inclusion of config.h, config.h includes eu-config.h.  */
+#ifdef HAVE_CONFIG_H
+#ifndef EU_CONFIG_H
+# include <config.h>
+#endif
+#endif
 
 #include <errno.h>
 #include <stdbool.h>
-- 
2.48.1

Reply via email to