diff options
| author | Jakob Kaivo <jkk@ung.org> | 2024-05-27 12:49:46 -0400 |
|---|---|---|
| committer | Jakob Kaivo <jkk@ung.org> | 2024-05-27 12:49:46 -0400 |
| commit | 04e5527eeca240ca81b0b95b58c50ef6a16b8030 (patch) | |
| tree | 3623519b07b9f3c027fa13fac925923dd05a3baa /src/stdio/putc_unlocked.c | |
| parent | 9b784a3affb4027c9bc40fba2b272abe7e580ece (diff) | |
handle UB for invalid fflush() operations and mixing input and output without intervening fflush() or repositioning
Diffstat (limited to 'src/stdio/putc_unlocked.c')
| -rw-r--r-- | src/stdio/putc_unlocked.c | 5 |
1 files changed, 5 insertions, 0 deletions
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') || |
