From 83c657c010a3f6ce647e305f7a77e73c65b8a001 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sun, 10 May 2020 22:29:14 +0200 Subject: [PATCH] Fix IO error handling in non-interactive reader This used to use fread(2) which returns size_t, but read(2) returns an ssize_t of -1 on error. Fixes #6990 --- src/reader.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/reader.cpp b/src/reader.cpp index 6cc6fabe9..48f89d7a2 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -3762,13 +3762,14 @@ static int read_ni(parser_t &parser, int fd, const io_chain_t &io) { std::string fd_contents; for (;;) { char buff[4096]; - size_t amt = read(fd, buff, sizeof buff); + ssize_t amt = read(fd, buff, sizeof buff); if (amt > 0) { fd_contents.append(buff, amt); } else if (amt == 0) { // EOF. break; } else { + assert(amt == -1); int err = errno; if (err == EINTR) { continue;