summaryrefslogtreecommitdiff
path: root/src/fold.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2003-08-11 14:35:52 +0000
committerJim Meyering <jim@meyering.net>2003-08-11 14:35:52 +0000
commitd761e22b60aa42e427c7b4f295016cabb64c0099 (patch)
tree6fa9de88177c82a33220ed965c667bceabd9f2e8 /src/fold.c
parent7f502e489c6ef9a3020a9ffc432fecb2c16df1fd (diff)
downloadcoreutils-d761e22b60aa42e427c7b4f295016cabb64c0099.tar.gz
fold -s -wN would infloop for N < 8 with TABs in the input.
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).
Diffstat (limited to 'src/fold.c')
-rw-r--r--src/fold.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/fold.c b/src/fold.c
index 8caed2f9e..538dcfdab 100644
--- a/src/fold.c
+++ b/src/fold.c
@@ -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;