From 88333ea13c746e6dfbb7ab26c2da2339793d4a95 Mon Sep 17 00:00:00 2001 From: "ziemowit.leszczynski" Date: Wed, 6 Nov 2024 13:19:59 +0100 Subject: [PATCH] stdio/file: fix write_buffer() JIRA: RTOS-892 --- stdio/file.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stdio/file.c b/stdio/file.c index 6b4dc349..e55c953a 100644 --- a/stdio/file.c +++ b/stdio/file.c @@ -532,10 +532,10 @@ static inline ssize_t write_buffer(FILE *stream, size_t writesz) if (err < writesz) { /* EAGAIN */ stream->flags |= F_ERROR; + } - if (err > 0) { - memmove(stream->buffer, stream->buffer + err, stream->bufpos); - } + if (err > 0 && stream->bufpos > 0) { + memmove(stream->buffer, stream->buffer + err, stream->bufpos); } } else {