* 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 | 8 ++++++++ lib/canonicalize.c | 29 ++++++++++------------------- 2 files changed, 18 insertions(+), 19 deletions(-)
diff --git a/ChangeLog b/ChangeLog index eb79c1b80a..d3a0d9b6c8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2026-05-10 Paul Eggert <[email protected]> + + 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 <[email protected]> string-buffer-reversed: Fix comments. diff --git a/lib/canonicalize.c b/lib/canonicalize.c index 06a6003152..e2e387b0d4 100644 --- a/lib/canonicalize.c +++ b/lib/canonicalize.c @@ -34,13 +34,6 @@ #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 @@ -51,11 +44,6 @@ # 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)) { -- 2.54.0
