From: Jim Meyering Date: Mon, 11 Aug 2003 14:35:52 +0000 (+0000) Subject: fold -s -wN would infloop for N < 8 with TABs in the input. X-Git-Tag: CPPI-1_11~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d761e22b60aa42e427c7b4f295016cabb64c0099;p=thirdparty%2Fcoreutils.git 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). --- diff --git a/src/fold.c b/src/fold.c index 8caed2f9e5..538dcfdabc 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;