From: Alexander Dahl Date: Fri, 20 Apr 2018 15:29:30 +0200 Subject: [U-Boot] [PATCH 1/2] tools: mkenvimage: Fix read() stdin error handling In-Reply-To: <20180420132931.22250-1-ada@thorsis.com> References: <20180420132931.22250-1-ada@thorsis.com> Message-ID: <20180420132931.22250-2-ada@thorsis.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On success read() returns the number of bytes read or zero for EOF. On error -1 is returned and errno is set, so the right way to test if read had failed is to test the return value instead of errno. Signed-off-by: Alexander Dahl --- tools/mkenvimage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/mkenvimage.c b/tools/mkenvimage.c index 8eee72e257..716cb73a5c 100644 --- a/tools/mkenvimage.c +++ b/tools/mkenvimage.c @@ -168,7 +168,7 @@ int main(int argc, char **argv) return EXIT_FAILURE; } readbytes = read(txt_fd, filebuf + filesize, readlen); - if (errno) { + if (readbytes < 0) { fprintf(stderr, "Error while reading stdin: %s\n", strerror(errno)); return EXIT_FAILURE; -- 2.11.0