dd: Fix backwards comparison when handling short writes - sbase - suckless unix… | |
git clone git://git.suckless.org/sbase | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 00995639fe3b885494d7dfeda7af618ba018fdd1 | |
parent 191f7e693b16dfc0f6242c4247ceded99e69878c | |
Author: Michael Forney <[email protected]> | |
Date: Sun, 4 Dec 2022 00:32:21 -0800 | |
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. | |
Diffstat: | |
M dd.c | 2 +- | |
1 file changed, 1 insertion(+), 1 deletion(-) | |
--- | |
diff --git a/dd.c b/dd.c | |
@@ -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; |