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 {