]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
canonicalize: pacify -Wmaybe-uninitialized without ignoring
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 10 May 2026 17:35:50 +0000 (10:35 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 10 May 2026 22:56:14 +0000 (15:56 -0700)
* lib/canonicalize.c: Do not ignore -Wmaybe-uninitialized.
(IF_LINT): Remove; no longer used.
(canonicalize_filename_mode_stk): Use a single local rather than two.
Ordinarily portmanteau variables are iffy, but this one is a win.

ChangeLog
lib/canonicalize.c

index eb79c1b80a934ea3e012d5019c6e5ac6934d5d01..d3a0d9b6c8de2d67e61d00e17aab89b63e7f23e0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2026-05-10  Paul Eggert  <eggert@cs.ucla.edu>
+
+       canonicalize: pacify -Wmaybe-uninitialized without ignoring
+       * lib/canonicalize.c: Do not ignore -Wmaybe-uninitialized.
+       (IF_LINT): Remove; no longer used.
+       (canonicalize_filename_mode_stk): Use a single local rather than two.
+       Ordinarily portmanteau variables are iffy, but this one is a win.
+
 2026-05-10  Bruno Haible  <bruno@clisp.org>
 
        string-buffer-reversed: Fix comments.
index 06a600315267d5edce67cfed10d305db987f7cce..e2e387b0d4ea9d528dc020969ed186643ab8fff4 100644 (file)
 #include "hashcode-file.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
 # define SLASHES "/"
 #endif
 
-/* Avoid false GCC warning "'end_idx' may be used uninitialized".  */
-#if _GL_GNUC_PREREQ (4, 7)
-# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
-#endif
-
 /* Return true if FILE's existence can be shown, false (setting errno)
    otherwise.  Follow symbolic links.  */
 static bool
@@ -277,7 +265,11 @@ canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode,
   bool logical = (can_mode & CAN_NOLINKS) != 0;
 
   int num_links = 0;
-  bool end_in_extra_buffer = false;
+
+  /* If nonnegative, the nonnegative offset (or former offset) in
+     BUFS->extra of the component end.  It never goes negative after
+     becoming nonnegative.  */
+  ptrdiff_t end_extra_offset = -1;
 
   for (; *start;)
     {
@@ -378,9 +370,8 @@ 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 IF_LINT (= 0);
-              if (end_in_extra_buffer)
-                end_idx = end - extra_buf;
+              if (0 <= end_extra_offset)
+                end_extra_offset = end - extra_buf;
               size_t len = strlen (end);
               if (INT_ADD_OVERFLOW (len, n))
                 xalloc_die ();
@@ -390,13 +381,13 @@ canonicalize_filename_mode_stk (const char *name, canonicalize_mode_t can_mode,
                     xalloc_die ();
                   extra_buf = bufs->extra.data;
                 }
-              if (end_in_extra_buffer)
-                end = extra_buf + end_idx;
+              if (0 <= end_extra_offset)
+                end = extra_buf + end_extra_offset;
 
               /* Careful here, end may be a pointer into extra_buf... */
               memmove (&extra_buf[n], end, len + 1);
               name = end = memcpy (extra_buf, buf, n);
-              end_in_extra_buffer = true;
+              end_extra_offset = 0;
 
               if (IS_ABSOLUTE_FILE_NAME (buf))
                 {