Hi Paul,
When looking at this I noticed confusing code in lseek_copy()
which seems like it might not be accounting for non zero SRC_POS.
I know we don't use non zero offsets yet, but does the attached make sense?
thanks,
Padraig
From 2bb2b4e1a0ca0067a30eceab4aa2fb4c4110cd6a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]>
Date: Mon, 3 Nov 2025 22:42:22 +0000
Subject: [PATCH] maint: fix hole reference condition with non zero copy offset
* src/copy-file-data.c (lseek_copy): hole_start is initialized
only when ext_start == ipos.
(infer_scantype): Update the hole_start initialization to
the more logically correct POS, even though that init
is only needed to suppress a -Wmaybe-uninitialized warning.
Note gcc 15.2 at least doesn't seem to need that suppression.
---
src/copy-file-data.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/copy-file-data.c b/src/copy-file-data.c
index c46b7edc5..e94b73025 100644
--- a/src/copy-file-data.c
+++ b/src/copy-file-data.c
@@ -338,7 +338,7 @@ lseek_copy (int src_fd, int dest_fd, char **abuf, idx_t buf_size,
for (off_t ext_start = scan_inference->ext_start;
0 <= ext_start && ext_start < max_ipos; )
{
- off_t ext_end = (ext_start == 0
+ off_t ext_end = (ext_start == ipos
? scan_inference->hole_start
: lseek (src_fd, ext_start, SEEK_HOLE));
if (0 <= ext_end)
@@ -496,7 +496,7 @@ infer_scantype (int fd, struct stat const *sb, off_t pos,
}
else if (pos < scan_inference->ext_start || errno == ENXIO)
{
- scan_inference->hole_start = 0; /* Pacify -Wmaybe-uninitialized. */
+ scan_inference->hole_start = pos; /* Pacify -Wmaybe-uninitialized. */
return LSEEK_SCANTYPE;
}
else if (errno != EINVAL && !is_ENOTSUP (errno))
--
2.51.1