summaryrefslogtreecommitdiff
path: root/Userland/fgrep.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-04-25 14:07:17 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-04-25 14:07:17 +0200
commitaa84e2fc64bb778aabd7c4bdffede94d5b98f0ed (patch)
treec0a7301b08a1b27f7ff5d48dcbc56d3a87384539 /Userland/fgrep.cpp
parentd5578826afe5c974d63cf2ab6656e16260c3cc39 (diff)
downloadserenity-aa84e2fc64bb778aabd7c4bdffede94d5b98f0ed.zip
fgrep: Don't repeat old incoming data if fgets() failed.
Diffstat (limited to 'Userland/fgrep.cpp')
-rw-r--r--Userland/fgrep.cpp6
1 files changed, 4 insertions, 2 deletions
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 <stdio.h>
#include <string.h>
#include <unistd.h>
+#include <assert.h>
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;
}