From c7a07bf214ef9b3fabc15c8e70f696ede9644c2c Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Sun, 29 Oct 2023 14:19:14 +0100 Subject: LibC: Bug fix, make sure to invalidate cache if it skips using it Since when the cache gets skipped the offset in the file increases far outside of the reach of the current cache. Therefore the current cache should be discarded. --- userland/libc/stdio/stdin.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'userland/libc/stdio') diff --git a/userland/libc/stdio/stdin.c b/userland/libc/stdio/stdin.c index 98189e2..2ced1a0 100644 --- a/userland/libc/stdio/stdin.c +++ b/userland/libc/stdio/stdin.c @@ -31,7 +31,12 @@ size_t read_fd(FILE *f, unsigned char *s, size_t l) { // equal to the cache block size. This avoids doing a bunch of extra // syscalls if (l >= 4096) { - return non_cache_read_fd(f, s, l); + // Invalidate the cache +f->read_buffer_stored = 0; + + size_t rc = non_cache_read_fd(f, s, l); + f->offset_in_file += rc; + return rc; } if (!f->read_buffer) { -- cgit v1.2.3