summaryrefslogtreecommitdiff
path: root/src/stdio/getc_unlocked.c
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2024-05-27 12:49:46 -0400
committerJakob Kaivo <jkk@ung.org>2024-05-27 12:49:46 -0400
commit04e5527eeca240ca81b0b95b58c50ef6a16b8030 (patch)
tree3623519b07b9f3c027fa13fac925923dd05a3baa /src/stdio/getc_unlocked.c
parent9b784a3affb4027c9bc40fba2b272abe7e580ece (diff)
handle UB for invalid fflush() operations and mixing input and output without intervening fflush() or repositioning
Diffstat (limited to 'src/stdio/getc_unlocked.c')
-rw-r--r--src/stdio/getc_unlocked.c6
1 files changed, 6 insertions, 0 deletions
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;