commit fb16e7c6ad0e8d27cba8ee6279f71f88c7f95fd7
Author:     Michael Forney <[email protected]>
AuthorDate: Wed Apr 12 20:13:51 2023 -0700
Commit:     Michael Forney <[email protected]>
CommitDate: Wed Apr 12 20:47:34 2023 -0700

    dd: Consider block count in inner read loop
    
    When ibs is smaller than obs, checking the block count in the outer
    loop is not sufficient; we need to break out of the inner read loop
    once we've read the specified number of blocks.
    
    Thanks to phoebos for reporting this issue.

diff --git a/dd.c b/dd.c
index 350843b..36eb409 100644
--- a/dd.c
+++ b/dd.c
@@ -173,8 +173,12 @@ main(int argc, char *argv[])
                        eprintf("lseek:");
                /* XXX: handle non-seekable files */
        }
-       while (!eof && (count == -1 || ifull + ipart < count)) {
+       while (!eof) {
                while (ipos - opos < obs) {
+                       if (ifull + ipart == count) {
+                               eof = 1;
+                               break;
+                       }
                        ret = read(ifd, buf + ipos, ibs);
                        if (ret == 0) {
                                eof = 1;

Reply via email to