On 03/11/2025 21:39, Bruno Haible via GNU coreutils General Discussion wrote:
Hi,
My coreutils CI contains a "make distcheck" step. Up to now, it was
running on Ubuntu 22.04, with gcc 11.x as compiler. This week, due
to last week's 3 changes to src/copy-file-data.c, there is an error.
I can reproduce it with a gcc 11.5.0 built from source:
src/copy-file-data.c: In function 'copy_file_data':
src/copy-file-data.c:428:50: error: 'scan_inference.ext_start' may be used
uninitialized in this function [-Werror=maybe-uninitialized]
The warning is gone with gcc 12 or newer. I'm switching the CI over to
Ubuntu 24.04. But I nevertheless wanted to give you a notice.
I'm surprised any of those 3 changes introduced such an error.
Perhaps the function size was changed which impacted inlining,
thus triggering cross procedural analysis issues.
I see we already have a suppression in infer_scantype,
so I suppose we could augment with something like the following,
as the ext_start is trivially initialized after,
so we're unlikely to hide any logic errors by doing this.
I notice with GCC 15.2 we get no warnings with all hacks removed.
diff --git a/src/copy-file-data.c b/src/copy-file-data.c
index e94b73025..26c8660be 100644
--- a/src/copy-file-data.c
+++ b/src/copy-file-data.c
@@ -462,6 +462,9 @@ static enum scantype
infer_scantype (int fd, struct stat const *sb, off_t pos,
struct scan_inference *scan_inference)
{
+ /* Pacify -Wmaybe-uninitialized. Not needed with GCC >= 15.2. */
+ IF_LINT (scan_inference->ext_start = scan_inference->hole_start = -1);
+
/* Try SEEK_HOLE only if this heuristic
suggests the file is sparse. */
if (! (HAVE_STRUCT_STAT_ST_BLOCKS