aboutsummaryrefslogtreecommitdiff
path: root/toys/posix
diff options
context:
space:
mode:
authorRobin Hsu <robinhsu@google.com>2021-03-11 18:50:38 +0800
committerRob Landley <rob@landley.net>2021-03-12 02:44:53 -0600
commit56ef8fcedc48bed353e3ccc694a8db3f322fae6f (patch)
tree1040270be276135424a3b4e9d4daba33598e0695 /toys/posix
parent8c2825c496ae4fb91483dee68d5c171ba6c0fd77 (diff)
downloadtoybox-56ef8fcedc48bed353e3ccc694a8db3f322fae6f.tar.gz
Fix grep bug testing errno before check status
It's legal for a system call to set non-zero errno and return a good status. The caller (grep) should check return status first. Test: 2000 loops of greping 1000+ lines each loop Signed-off-by: Robin Hsu <robinhsu@google.com> Change-Id: I55f7cd5d8a6289c5e8a21ed3057e995a75b9b4fa
Diffstat (limited to 'toys/posix')
-rw-r--r--toys/posix/grep.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/toys/posix/grep.c b/toys/posix/grep.c
index cd8928a1..52d10139 100644
--- a/toys/posix/grep.c
+++ b/toys/posix/grep.c
@@ -154,7 +154,7 @@ static void do_grep(int fd, char *name)
lcount++;
errno = 0;
ulen = len = getdelim(&line, &ulen, TT.indelim, file);
- if (errno) perror_msg("%s", name);
+ if (len == -1 && errno) perror_msg("%s", name);
if (len<1) break;
if (line[ulen-1] == TT.indelim) line[--ulen] = 0;