dd: Always move excess to beginning of buffer after read/write loops

Otherwise, while we may have enough room for at least one input
block, we may not have enough room for an output block.
This commit is contained in:
Michael Forney 2021-04-28 01:41:26 -07:00
parent 7ef4038fb5
commit 4b76652eff
1 changed files with 3 additions and 4 deletions

3
dd.c
View File

@ -222,12 +222,11 @@ main(int argc, char *argv[])
ofull++;
opos += ret;
} while ((eof && ipos < opos) || (!eof && ipos - opos >= obs));
if (len - ipos < ibs) {
if (opos < ipos)
memmove(buf, buf + opos, ipos - opos);
ipos -= opos;
opos = 0;
}
}
summary();
return 0;