From 7ad212ff638d38c9b86496a2fffcf7778f1cd4a6 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Sat, 20 May 2023 07:28:30 +0100 Subject: [PATCH] tail: Count lines correctly when file ends with two or more newlines Previously, an extra line would be displayed when a file ended in more than one newline. --- Userland/Utilities/tail.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Userland/Utilities/tail.cpp b/Userland/Utilities/tail.cpp index c9ad2abf0b8..6ed396c5350 100644 --- a/Userland/Utilities/tail.cpp +++ b/Userland/Utilities/tail.cpp @@ -33,7 +33,7 @@ static ErrorOr find_seek_pos(Core::File& file, int wanted_lines) TRY(file.seek(pos - 1, SeekMode::SetPosition)); auto ch = TRY(file.read_value()); - if (ch == '\n' && (end - pos) > 1) { + if (ch == '\n' && (end - pos) > 0) { lines++; if (lines == wanted_lines) break;