From 198935eb30dfcb367ae448c9b5a02244881d8ce7 Mon Sep 17 00:00:00 2001 From: apio Date: Tue, 8 Aug 2023 10:39:15 +0200 Subject: [PATCH] libc: Reset the read buffer even when read() returns an error This fixes the same data being read multiple times if an error was returned --- libc/src/stdio.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libc/src/stdio.cpp b/libc/src/stdio.cpp index d21960ac..3a9365e8 100644 --- a/libc/src/stdio.cpp +++ b/libc/src/stdio.cpp @@ -135,6 +135,8 @@ static ssize_t read_data_into_buffer(FILE* stream) stream->_buf.index = 0; ssize_t nread = read(stream->_fd, stream->_buf.buffer, stream->_buf.capacity); if (nread >= 0) stream->_buf.size = nread; + else + stream->_buf.size = 0; stream->_buf.status |= FileStatusFlags::LastRead; return nread; }