[hackers] [sbase] dd: Fix backwards comparison when handling short writes || Michael Forney

From: <git_AT_suckless.org>
Date: Thu, 13 Apr 2023 05:12:40 +0200 (CEST)

commit 00995639fe3b885494d7dfeda7af618ba018fdd1
Author: Michael Forney <mforney_AT_mforney.org>
AuthorDate: Sun Dec 4 00:32:21 2022 -0800
Commit: Michael Forney <mforney_AT_mforney.org>
CommitDate: Wed Apr 12 20:09:51 2023 -0700

    dd: Fix backwards comparison when handling short writes
    
    ipos is always ahead of opos, so the left side of this condition
    was never true. This only mattered when we get short writes, since
    on EOF we always have less than a full output block, so it takes
    only one normal write.

diff --git a/dd.c b/dd.c
index 6061048..350843b 100644
--- a/dd.c
+++ b/dd.c
_AT_@ -221,7 +221,7 @@ main(int argc, char *argv[])
                         else
                                 ofull++;
                         opos += ret;
- } while ((eof && ipos < opos) || (!eof && ipos - opos >= obs));
+ } while (ipos - opos >= (eof ? 1 : obs));
                 if (opos < ipos)
                         memmove(buf, buf + opos, ipos - opos);
                 ipos -= opos;
Received on Thu Apr 13 2023 - 05:12:40 CEST

This archive was generated by hypermail 2.3.0 : Thu Apr 13 2023 - 05:12:55 CEST