From: Jim Meyering Date: Sat, 21 Oct 2000 19:57:41 +0000 (+0000) Subject: The command, `yes ''|./cat -n' would stop printing after INT_MAX lines. X-Git-Tag: TEXTUTILS-2_0_8~39 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=13e80acf0777bb5aed3d6c766064ed23d7ae0739;p=thirdparty%2Fcoreutils.git The command, `yes ''|./cat -n' would stop printing after INT_MAX lines. (cat): Never let `newlines' exceed 3. --- diff --git a/src/cat.c b/src/cat.c index 84634c2cc2..9587f78652 100644 --- a/src/cat.c +++ b/src/cat.c @@ -350,13 +350,21 @@ cat ( if (++newlines > 0) { - /* Are multiple adjacent empty lines to be substituted by - single ditto (-s), and this was the second empty line? */ - - if (squeeze_empty_lines && newlines >= 2) + if (newlines >= 2) { - ch = *bpin++; - continue; + /* Limit this to 2 here. Otherwise, with lots of + consecutive newlines, the counter could wrap + around at INT_MAX. */ + newlines = 2; + + /* Are multiple adjacent empty lines to be substituted + by single ditto (-s), and this was the second empty + line? */ + if (squeeze_empty_lines) + { + ch = *bpin++; + continue; + } } /* Are line numbers to be written at empty lines (-n)? */