From 04e5527eeca240ca81b0b95b58c50ef6a16b8030 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Mon, 27 May 2024 12:49:46 -0400 Subject: handle UB for invalid fflush() operations and mixing input and output without intervening fflush() or repositioning --- src/stdio/putc_unlocked.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/stdio/putc_unlocked.c') diff --git a/src/stdio/putc_unlocked.c b/src/stdio/putc_unlocked.c index fffb2618..9a7b3a60 100644 --- a/src/stdio/putc_unlocked.c +++ b/src/stdio/putc_unlocked.c @@ -17,7 +17,12 @@ int putc_unlocked(int c, FILE *stream) SIGNAL_SAFE(0); ASSERT_NONNULL(stream); + + if (stream->operation == OP_INPUT) { + UNDEFINED("attempted output on stream immediately after input"); + } + stream->operation = OP_OUTPUT; stream->buf[stream->bpos++] = ch; if (stream->bpos == stream->bsize || (stream->bmode == _IOLBF && ch == '\n') || -- cgit v1.2.1