]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
fold -s -wN would infloop for N < 8 with TABs in the input.
authorJim Meyering <jim@meyering.net>
Mon, 11 Aug 2003 14:35:52 +0000 (14:35 +0000)
committerJim Meyering <jim@meyering.net>
Mon, 11 Aug 2003 14:35:52 +0000 (14:35 +0000)
E.g., this would not terminate: printf 'a\tb' | fold -w2 -s

(fold_file): Move contents of `else'-block
out of conditional so it's used also for --spaces (-s).

src/fold.c

index 8caed2f9e5fd7aa571fc7970d1b827e5003cada0..538dcfdabc14715a9b11c6f65e9607e4b5290834 100644 (file)
@@ -1,5 +1,5 @@
 /* fold -- wrap each input line to fit in specified width.
-   Copyright (C) 91, 1995-2002 Free Software Foundation, Inc.
+   Copyright (C) 91, 1995-2003 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -193,14 +193,13 @@ fold_file (char *filename, int width)
                  goto rescan;
                }
            }
-         else
+
+         if (offset_out == 0)
            {
-             if (offset_out == 0)
-               {
-                 line_out[offset_out++] = c;
-                 continue;
-               }
+             line_out[offset_out++] = c;
+             continue;
            }
+
          line_out[offset_out++] = '\n';
          fwrite (line_out, sizeof (char), (size_t) offset_out, stdout);
          column = offset_out = 0;