]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(copy, copy_with_block, copy_with_block): Decrement pending_spaces only
authorJim Meyering <jim@meyering.net>
Wed, 24 Mar 1993 06:22:57 +0000 (06:22 +0000)
committerJim Meyering <jim@meyering.net>
Wed, 24 Mar 1993 06:22:57 +0000 (06:22 +0000)
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.

src/dd.c

index ba8d15e571ae820e94ac307fed3aa83dfbd8357d..4d78b8e40b5d22bf80fad1ade715bd223747ee1e 100644 (file)
--- 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);
        }