Hi,

dd doesn't error out if posix_fadvise() returns an error. Here is a patch for the fix.

fadvise64() always returns -1 on error, but not posix_fadvise().

Best regards
Frédéric
From 433160f4af26b89d5c52f71a9e44b5b60e1f9d71 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Yhuel?= <frederic.yh...@dalibo.com>
Date: Sun, 9 Mar 2025 17:59:15 +0100
Subject: [PATCH] dd: fix check of return value of posix_fadvise()

* src/dd.c: posix_fadvise() returns 0 on success, and an error number
  otherwise. Note that posix_fadvise() and fadvise64() are different
  in this respect.
---
 src/dd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/dd.c b/src/dd.c
index 4e914336b..bc37c0618 100644
--- a/src/dd.c
+++ b/src/dd.c
@@ -1092,7 +1092,7 @@ invalidate_cache (int fd, off_t len)
 #endif
    }
 
-  return adv_ret != -1 ? true : false;
+  return adv_ret == 0 ? true : false;
 }
 
 /* Read from FD into the buffer BUF of size SIZE, processing any
-- 
2.47.2

  • [PATCH] dd: fix chec... Frédéric Yhuel via GNU coreutils General Discussion
    • [PATCH] dd: fix... Frédéric Yhuel via GNU coreutils General Discussion
      • Re: [PATCH]... Pádraig Brady
        • Re: [PA... Frédéric Yhuel via GNU coreutils General Discussion
          • Re:... Pádraig Brady
            • ... Frédéric Yhuel via GNU coreutils General Discussion

Reply via email to