From 68de9008e753ad577e00da5f035b98a4d51512ec Mon Sep 17 00:00:00 2001 From: r-paiva Date: Thu, 29 Apr 2021 16:07:17 +0100 Subject: [PATCH] Utilities: Fix grep match when reading from stdin When reading from stdin, grep discards the last character, even if that character is not \n. This commit changes grep to no longer discard the last character from a line. --- Userland/Utilities/grep.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Userland/Utilities/grep.cpp b/Userland/Utilities/grep.cpp index a2483650bce..a7eef6c56d4 100644 --- a/Userland/Utilities/grep.cpp +++ b/Userland/Utilities/grep.cpp @@ -177,7 +177,7 @@ int main(int argc, char** argv) ScopeGuard free_line = [line] { free(line); }; while ((nread = getline(&line, &line_len, stdin)) != -1) { VERIFY(nread > 0); - StringView line_view(line, nread - 1); + StringView line_view(line, nread); bool is_binary = line_view.contains(0); if (is_binary && binary_mode == BinaryFileMode::Skip)