From: Pádraig Brady
Date: Wed, 28 Aug 2024 11:10:43 +0000 (+0100)
Subject: avoid GCC -Wmaybe-uninitialized false positives with LTO
X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=4602765093f04e597f87d78cf29d21eea03b6fa4;p=gnulib.git
avoid GCC -Wmaybe-uninitialized false positives with LTO
Avoids false warnings with GCC 14.2.1 with -flto
* lib/canonicalize.c: Initialize END_IDX.
* lib/getndelim2.c: Initialize C.
---
diff --git a/ChangeLog b/ChangeLog
index a6e17128ad..07e84fb216 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-08-28 Pádraig Brady
+
+ avoid GCC -Wmaybe-uninitialized false positives with LTO
+ Avoids false warnings with GCC 14.2.1 with -flto
+
+ * lib/canonicalize.c: Initialize END_IDX.
+ * lib/getndelim2.c: Initialize C.
+
2024-08-28 Bruno Haible
threads-h: Don't override the C++ keyword 'thread_local'.
diff --git a/lib/canonicalize.c b/lib/canonicalize.c
index 7d2a629024..2572b40558 100644
--- a/lib/canonicalize.c
+++ b/lib/canonicalize.c
@@ -34,6 +34,13 @@
#include "hash-triple.h"
#include "xalloc.h"
+/* Suppress bogus GCC -Wmaybe-uninitialized warnings. */
+#if defined GCC_LINT || defined lint
+# define IF_LINT(Code) Code
+#else
+# define IF_LINT(Code) /* empty */
+#endif
+
#ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT
# define DOUBLE_SLASH_IS_DISTINCT_ROOT false
#endif
@@ -367,7 +374,7 @@ canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode,
buf[n] = '\0';
char *extra_buf = bufs->extra.data;
- idx_t end_idx;
+ idx_t end_idx IF_LINT (= 0);
if (end_in_extra_buffer)
end_idx = end - extra_buf;
size_t len = strlen (end);
diff --git a/lib/getndelim2.c b/lib/getndelim2.c
index 89989aefdd..db61e2a5e6 100644
--- a/lib/getndelim2.c
+++ b/lib/getndelim2.c
@@ -47,8 +47,10 @@
#include "memchr2.h"
/* Avoid false GCC warning "'c' may be used uninitialized". */
-#if _GL_GNUC_PREREQ (4, 7)
-# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+#if defined GCC_LINT || defined lint
+# define IF_LINT(Code) Code
+#else
+# define IF_LINT(Code) /* empty */
#endif
/* The maximum value that getndelim2 can return without suffering from
@@ -102,7 +104,7 @@ getndelim2 (char **lineptr, size_t *linesize, size_t offset, size_t nmax,
/* Here always ptr + size == read_pos + nbytes_avail.
Also nbytes_avail > 0 || size < nmax. */
- int c;
+ int c IF_LINT (= EOF);
const char *buffer;
size_t buffer_len;