From: Jim Meyering Date: Wed, 24 Mar 1993 06:22:57 +0000 (+0000) Subject: (copy, copy_with_block, copy_with_block): Decrement pending_spaces only X-Git-Tag: FILEUTILS-3_8_3b~101 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=82bdb546d9a76094f1c40413fa2bd56cbbd93eaa;p=thirdparty%2Fcoreutils.git (copy, copy_with_block, copy_with_block): Decrement pending_spaces only if it's > 0. The following command didn't terminate: perl -e 'print "a a\n";'| dd of=/dev/null ibs=1 cbs=3 conv=unblock With suggestions from Chris Weber , Marlys.A.Nelson@uwrf.edu, and Albert-Lunde@nwu.edu. --- diff --git a/src/dd.c b/src/dd.c index ba8d15e571..4d78b8e40b 100644 --- a/src/dd.c +++ b/src/dd.c @@ -618,8 +618,11 @@ copy () /* If the final input line didn't end with a '\n', pad the output block to `conversion_blocksize' chars. */ int pending_spaces = max (0, conversion_blocksize - col); - while (pending_spaces--) - output_char (space_character); + while (pending_spaces) + { + output_char (space_character); + --pending_spaces; + } } if ((conversions_mask & C_UNBLOCK) && col == conversion_blocksize) @@ -690,8 +693,11 @@ copy_with_block (buf, nread) if (*buf == newline_character) { int pending_spaces = max (0, conversion_blocksize - col); - while (pending_spaces--) - output_char (space_character); + while (pending_spaces) + { + output_char (space_character); + --pending_spaces; + } col = 0; } else @@ -732,12 +738,12 @@ copy_with_unblock (buf, nread) pending_spaces++; else { - if (pending_spaces) + /* `c' is the character after a run of spaces that were not + at the end of the conversion buffer. Output them. */ + while (pending_spaces) { - /* `c' is the character after a run of spaces that were not - at the end of the conversion buffer. Output them. */ - while (pending_spaces--) - output_char (space_character); + output_char (space_character); + --pending_spaces; } output_char (c); }