Hi Dmitry,

On Fri, Apr 04, 2025 at 04:07:26PM +0300, Dmitry V. Levin wrote:
> On Fri, Apr 04, 2025 at 01:55:48PM +0200, Mark Wielaard wrote:
> > So to be (pedantically) correct should we include the attached?
> 
> Yes, this should be fine, along with
> 
> --- a/lib/crc32.c
> +++ b/lib/crc32.c
> @@ -28 +28 @@
> -#if HAVE_CONFIG_H
> +#ifdef HAVE_CONFIG_H

Thanks, I had missed that one.
Added and pushed as attached.

Cheers,

Mark
>From f33f4c85581045ae493e7f12c6ba1bf5829d8192 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/crc32.c: Use #ifdef HAVE_CONFIG_H instead of #if.
       * 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.

Suggested-by: Dmitry V. Levin <l...@strace.io>
Signed-off-by: Mark Wielaard <m...@klomp.org>
---
 lib/crc32.c  | 2 +-
 lib/error.c  | 4 +++-
 lib/system.h | 7 ++++++-
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/lib/crc32.c b/lib/crc32.c
index 758602ea02fd..eae658225f76 100644
--- a/lib/crc32.c
+++ b/lib/crc32.c
@@ -25,7 +25,7 @@
    the GNU Lesser General Public License along with this program.  If
    not, see <http://www.gnu.org/licenses/>.  */
 
-#if HAVE_CONFIG_H
+#ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
 
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.49.0

Reply via email to