]> Savannah Git Hosting - gnulib.git/commitdiff
avoid GCC -Wmaybe-uninitialized false positives with LTO
authorPádraig Brady <P@draigBrady.com>
Wed, 28 Aug 2024 11:10:43 +0000 (12:10 +0100)
committerPádraig Brady <P@draigBrady.com>
Thu, 29 Aug 2024 01:15:40 +0000 (02:15 +0100)
Avoids false warnings with GCC 14.2.1 with -flto

* lib/canonicalize.c: Initialize END_IDX.
* lib/getndelim2.c: Initialize C.

ChangeLog
lib/canonicalize.c
lib/getndelim2.c

index a6e17128ad1362aea9d6e44b0cc136e383a38876..07e84fb216a28219360968fcb79eba98659fc660 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-08-28  Pádraig Brady  <P@draigBrady.com>
+
+       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  <bruno@clisp.org>
 
        threads-h: Don't override the C++ keyword 'thread_local'.
index 7d2a629024b18adde01a5c9c9aa3de2c169ab878..2572b4055851634a73ef1929d8b0632b85a12a03 100644 (file)
 #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);
index 89989aefdd5ea3fa78f2bbad1575a9052207cc88..db61e2a5e6ed952350dbaa35187365c1a4b25d4e 100644 (file)
 #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;