]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(elide_tail_lines_pipe): Fix a thinko.
authorJim Meyering <jim@meyering.net>
Wed, 21 May 2003 09:29:50 +0000 (09:29 +0000)
committerJim Meyering <jim@meyering.net>
Wed, 21 May 2003 09:29:50 +0000 (09:29 +0000)
This sort of thing is why it'd be *Really Good* to factor
out the common code used here and in tail.c.

src/head.c

index 1497a712a92e86325e2766147cf13e1876b40f7b..7d58aefa94c395c3589a8f5177ebc6328dd7e29f 100644 (file)
@@ -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;