summaryrefslogtreecommitdiff
path: root/src/stdio/fflush.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/fflush.c
parent9b784a3affb4027c9bc40fba2b272abe7e580ece (diff)
handle UB for invalid fflush() operations and mixing input and output without intervening fflush() or repositioning
Diffstat (limited to 'src/stdio/fflush.c')
-rw-r--r--src/stdio/fflush.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/stdio/fflush.c b/src/stdio/fflush.c
index e13f8979..cb5f49c6 100644
--- a/src/stdio/fflush.c
+++ b/src/stdio/fflush.c
@@ -27,6 +27,14 @@ int fflush(FILE *stream)
return 0;
}
+ if (!stream->write) {
+ UNDEFINED("attempt to fflush() an input stream");
+ }
+
+ if (stream->read && stream->operation == OP_INPUT) {
+ UNDEFINED("attempt to fflush() an update stream after input");
+ }
+
if (stream->bpos == 0) {
return 0;
}