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/getc_unlocked.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/stdio/getc_unlocked.c') diff --git a/src/stdio/getc_unlocked.c b/src/stdio/getc_unlocked.c index 140e1a4d..0e68eb79 100644 --- a/src/stdio/getc_unlocked.c +++ b/src/stdio/getc_unlocked.c @@ -19,6 +19,12 @@ int getc_unlocked(FILE * stream) return EOF; } + if (stream->operation == OP_OUTPUT) { + UNDEFINED("attempted input on stream immediately after output"); + } + + stream->operation = OP_INPUT; + if (read(stream->fd, &c, sizeof(c)) != 1) { stream->err = 1; return EOF; -- cgit v1.2.1