[hackers] [sbase] dd: Consider block count in inner read loop || Michael Forney
commit fb16e7c6ad0e8d27cba8ee6279f71f88c7f95fd7
Author: Michael Forney <mforney_AT_mforney.org>
AuthorDate: Wed Apr 12 20:13:51 2023 -0700
Commit: Michael Forney <mforney_AT_mforney.org>
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
_AT_@ -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;
Received on Thu Apr 13 2023 - 05:50:48 CEST
This archive was generated by hypermail 2.3.0
: Thu Apr 13 2023 - 06:00:38 CEST