On 2025-09-18 13:34, Bruno Haible wrote:
The compilers on FreeBSD 11 and OpenBSD 7.6 (at least) report give this
warning:

../src/copy-file-data.c:585:7: warning: variable 'result' is used uninitialized 
whenever 'if' condition is false [-Wsometimes-uninitialized]

I'm not seeing that on OpenBSD 7.7 which has clang version 16.0.6.

I'm not a fan of 'abort' calls merely to pacify older, buggier compilers. That being said, a less-intrusive pacification change would be fine. Does the attached patch work for you? It uses 'unreachable' instead of 'abort' (except on compilers that lack 'unreachable' and where 'unreachable' is #defined to be 'abort', but that's OK).

While we're on the subject of bogus OpenBSD warnings, perhaps we should do something about OpenBSD's style nattering. Linker warnings like this:

warning: strcpy() is almost always misused, please use strlcpy()

are a waste of time for us, and we can fix them in Gnulib by defining our own strcpy that overrides OpenBSD's.
diff --git a/src/copy-file-data.c b/src/copy-file-data.c
index 44b542de0..1eefd3071 100644
--- a/src/copy-file-data.c
+++ b/src/copy-file-data.c
@@ -571,18 +571,19 @@ copy_file_data (int ifd, struct stat const *ist, off_t ipos, char const *iname,
   intmax_t result;
   off_t hole_size = 0;
 
-#ifdef SEEK_HOLE
   if (scantype == LSEEK_SCANTYPE)
-    result = lseek_copy (ifd, ofd, &buf, buf_size,
-                         ipos, ibytes, &scan_inference, ist->st_size,
-                         make_holes ? x->sparse_mode : SPARSE_NEVER,
-                         x->reflink_mode != REFLINK_NEVER,
-                         iname, oname, &hole_size, debug);
+    {
+#ifdef SEEK_HOLE
+      result = lseek_copy (ifd, ofd, &buf, buf_size,
+                           ipos, ibytes, &scan_inference, ist->st_size,
+                           make_holes ? x->sparse_mode : SPARSE_NEVER,
+                           x->reflink_mode != REFLINK_NEVER,
+                           iname, oname, &hole_size, debug);
 #else
-  assume (scantype != LSEEK_SCANTYPE);
+      unreachable ();
 #endif
-
-  if (scantype != LSEEK_SCANTYPE)
+    }
+  else
     result = sparse_copy (ifd, ofd, &buf, buf_size,
                           x->reflink_mode != REFLINK_NEVER,
                           iname, oname, ibytes,

Reply via email to