From f6abdc030897e5b141f11b30906933863d5ed894 Mon Sep 17 00:00:00 2001 From: Georges Savoundararadj Date: Tue, 19 May 2026 12:28:26 +0000 Subject: [PATCH] Replace rewind() with fseek() for error handling rewind() is equivalent to (void)fseek(fp, 0L, SEEK_SET) and silently discards any seek error. Replace with fseek() and check the return value in readfile.h and fileio.c so that a failed seek propagates to the caller via the existing fail path. Signed-off-by: Georges Savoundararadj --- include/flatcc/support/readfile.h | 2 +- src/compiler/fileio.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/flatcc/support/readfile.h b/include/flatcc/support/readfile.h index 209875fb1..a262b2152 100644 --- a/include/flatcc/support/readfile.h +++ b/include/flatcc/support/readfile.h @@ -32,7 +32,7 @@ static char *readfile(const char *filename, size_t max_size, size_t *size_out) if (max_size > 0 && size > max_size) { goto fail; } - rewind(fp); + if (fseek(fp, 0L, SEEK_SET)) goto fail; buf = (char *)malloc(size ? size : 1); if (!buf) { goto fail; diff --git a/src/compiler/fileio.c b/src/compiler/fileio.c index 56d88c114..c9edaf1b8 100644 --- a/src/compiler/fileio.c +++ b/src/compiler/fileio.c @@ -197,7 +197,7 @@ char *fb_read_file(const char *filename, size_t max_size, size_t *size_out) if (max_size > 0 && size > max_size) { goto fail; } - rewind(fp); + if (fseek(fp, 0L, SEEK_SET)) goto fail; buf = malloc(size ? size : 1); if (!buf) { goto fail;