From 7848df8f2a5bc3b95e2b05b8876708bb93230de7 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Sun, 16 Aug 2020 12:38:34 -0400 Subject: check return of write() properly set err on stream if write error occurs reset bpos to 0 --- src/stdio/putc_unlocked.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/stdio/putc_unlocked.c b/src/stdio/putc_unlocked.c index cf8c9cb4..4a3937e8 100644 --- a/src/stdio/putc_unlocked.c +++ b/src/stdio/putc_unlocked.c @@ -22,10 +22,12 @@ int putc_unlocked(int c, FILE *stream) if (stream->bpos == stream->bsize || (stream->bmode == _IOLBF && ch == '\n') || (stream->bmode == _IONBF)) { - if (write(stream->fd, stream->buf, stream->bpos) != 1) { + if (write(stream->fd, stream->buf, stream->bpos) < 0) { /* errno handled by write() */ + stream->err = 1; return EOF; } + stream->bpos = 0; } return ch; -- cgit v1.2.1