summaryrefslogtreecommitdiff
path: root/src/dd.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1993-03-24 06:22:57 +0000
committerJim Meyering <jim@meyering.net>1993-03-24 06:22:57 +0000
commit82bdb546d9a76094f1c40413fa2bd56cbbd93eaa (patch)
treef2a9b75f85ba371bc0162ace7214feddf63f8a3d /src/dd.c
parent38456f092f5a5200a20d234c671f72f0a909a5d3 (diff)
downloadcoreutils-82bdb546d9a76094f1c40413fa2bd56cbbd93eaa.tar.xz
(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 <weber@bucknell.edu>, Marlys.A.Nelson@uwrf.edu, and Albert-Lunde@nwu.edu.
Diffstat (limited to 'src/dd.c')
-rw-r--r--src/dd.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/dd.c b/src/dd.c
index ba8d15e57..4d78b8e40 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);
}