From aa84e2fc64bb778aabd7c4bdffede94d5b98f0ed Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 25 Apr 2019 14:07:17 +0200 Subject: fgrep: Don't repeat old incoming data if fgets() failed. --- Userland/fgrep.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'Userland/fgrep.cpp') diff --git a/Userland/fgrep.cpp b/Userland/fgrep.cpp index 2d9c7bc5ea..8916d1131a 100644 --- a/Userland/fgrep.cpp +++ b/Userland/fgrep.cpp @@ -1,6 +1,7 @@ #include #include #include +#include int main(int argc, char** argv) { @@ -10,11 +11,12 @@ int main(int argc, char** argv) } for (;;) { char buf[4096]; - fgets(buf, sizeof(buf), stdin); - if (strstr(buf, argv[1])) + auto* str = fgets(buf, sizeof(buf), stdin); + if (str && strstr(str, argv[1])) write(1, buf, strlen(buf)); if (feof(stdin)) return 0; + ASSERT(str); } return 0; } -- cgit v1.2.3