From: Jim Meyering Date: Sat, 2 Aug 2003 19:53:52 +0000 (+0000) Subject: (cut_fields): Don't read again after encountering EOF. X-Git-Tag: CPPI-1_11~142 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aca28ca9ac235250ba848c707522edddbac70c42;p=thirdparty%2Fcoreutils.git (cut_fields): Don't read again after encountering EOF. E.g., `cut -f2' would do so. --- diff --git a/src/cut.c b/src/cut.c index bc7a26995a..e84d86131f 100644 --- a/src/cut.c +++ b/src/cut.c @@ -563,15 +563,15 @@ cut_fields (FILE *stream) unsigned int field_idx; int found_any_selected_field; int buffer_first_field; - int empty_input; found_any_selected_field = 0; field_idx = 1; c = getc (stream); - empty_input = (c == EOF); - if (c != EOF) - ungetc (c, stream); + if (c == EOF) + return; + + ungetc (c, stream); /* To support the semantics of the -s flag, we may have to buffer all of the first field to determine whether it is `delimited.' @@ -667,7 +667,7 @@ cut_fields (FILE *stream) else if (c == '\n' || c == EOF) { if (found_any_selected_field - || (!empty_input && !(suppress_non_delimited && field_idx == 1))) + || !(suppress_non_delimited && field_idx == 1)) putchar ('\n'); if (c == EOF) break;