From: Jim Meyering Date: Wed, 21 May 2003 09:29:50 +0000 (+0000) Subject: (elide_tail_lines_pipe): Fix a thinko. X-Git-Tag: v5.0.1~454 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=dadd6992a2618eaacff505d56dc73c6215071fdd;p=thirdparty%2Fcoreutils.git (elide_tail_lines_pipe): Fix a thinko. This sort of thing is why it'd be *Really Good* to factor out the common code used here and in tail.c. --- diff --git a/src/head.c b/src/head.c index 1497a712a9..7d58aefa94 100644 --- a/src/head.c +++ b/src/head.c @@ -555,8 +555,9 @@ elide_tail_lines_pipe (const char *filename, int fd, uintmax_t n_elide) goto free_lbuffers; } - /* Count the incomplete line on files that don't end with a newline. */ - if (last->buffer[last->nbytes - 1] != '\n') + /* If we read any bytes at all, count the incomplete line + on files that don't end with a newline. */ + if (last->nbytes && last->buffer[last->nbytes - 1] != '\n') { ++last->nlines; ++total_lines;