From 264edcf263bff02aebfe67f1d7343fbf0e96b5de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= Date: Wed, 28 Aug 2024 12:10:43 +0100 Subject: [PATCH] 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: Initicalise C. --- ChangeLog | 8 ++++++++ lib/canonicalize.c | 9 ++++++++- lib/getndelim2.c | 8 +++++--- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8a7f812b67..fdcc79134e 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: Initicalise C. + 2024-08-28 Bruno Haible doc: Add more details about O_EXEC and O_SEARCH. 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; -- 2.46.0