From 2454f481d06da7aadf8993d0b4fdcd97e60d74e7 Mon Sep 17 00:00:00 2001 From: Matthew Vernon Date: Fri, 7 Nov 2025 13:32:46 +0000 Subject: [PATCH] Fix 3x not checking fread return value Again, found by using newer build tooling. --- tsl.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tsl.c b/tsl.c index d5946a2..c0090c6 100644 --- a/tsl.c +++ b/tsl.c @@ -127,6 +127,7 @@ | \*----------------------------------------------------------------------*/ +#include #include #include #include @@ -286,7 +287,8 @@ int tsl_scan_concordance(const char *target, ref_t *sbuf, ref_t range_start, /* Read all the refs for this word */ /* Where do they end? */ fseek( cfp, (int)(inx_start + univ2int(cfh.data_ptr)), SEEK_SET ); - fread( tbuf, 1, rsize, cfp ); + if (fread( tbuf, 1, rsize, cfp ) < (size_t)rsize) + tsl_error(TRUE, "Reading %d refs: %s", rsize, strerror(errno)); /* Process the ref list. Expand compressed references. @@ -682,12 +684,14 @@ void tsl_init(char *dfname,char *path, const int memlimit) /* Allocate & initialize buffer for strings (all words) */ i=univ2int(cfh.index_ptr) - univ2int(cfh.word_ptr); cf_words = malloc( i ); - fread( cf_words, 1, i, cfp ); + if (fread( cf_words, 1, i, cfp ) < (size_t)i) + tsl_error( TRUE, "reading initialised buffer for strings"); /* Allocate & initialize buffer for index */ i=univ2int(cfh.data_ptr) - univ2int(cfh.index_ptr); cf_index = (short int *) malloc( i ); - fread( cf_index, 1, i, cfp ); + if (fread( cf_index, 1, i, cfp ) < (size_t)i) + tsl_error( TRUE, "reading initialised buffer for index"); /* Convert from Short_Univ_Int to short int */ sup = (Short_Univ_Int *) cf_index; for (i=0; i<=univ2int(cfh.word_cnt); i++) { -- 2.30.2