summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/tail.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/tail.c b/src/tail.c
index 4581845d1..5d86da2d4 100644
--- a/src/tail.c
+++ b/src/tail.c
@@ -848,9 +848,7 @@ start_lines (const char *pretty_filename, int fd, uintmax_t n_lines,
while (1)
{
char buffer[BUFSIZ];
- char *p = buffer;
size_t bytes_read = safe_read (fd, buffer, BUFSIZ);
- char *buffer_end = buffer + bytes_read;
if (bytes_read == 0) /* EOF */
return -1;
if (bytes_read == SAFE_READ_ERROR) /* error */
@@ -859,8 +857,11 @@ start_lines (const char *pretty_filename, int fd, uintmax_t n_lines,
return 1;
}
+ char *buffer_end = buffer + bytes_read;
+
*read_pos += bytes_read;
+ char *p = buffer;
while ((p = memchr (p, '\n', buffer_end - p)))
{
++p;