From 371c0f00545b70b67043765677a83a4bfa0bf827 Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Sun, 7 Jul 2024 15:26:44 +0200 Subject: Check the retval of fscanf() --- FICS/ratings.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'FICS') diff --git a/FICS/ratings.c b/FICS/ratings.c index 11896aa..931163c 100644 --- a/FICS/ratings.c +++ b/FICS/ratings.c @@ -340,8 +340,19 @@ load_ratings(void) } for (int i = 0; i < MAXHIST; i++) { - fscanf(fp, "%d %d %d %d", &sHist[i], &bHist[i], &wHist[i], + int ret, errno_save; + + errno = 0; + ret = fscanf(fp, "%d %d %d %d", &sHist[i], &bHist[i], &wHist[i], &lHist[i]); + errno_save = errno; + if (ret != 4) { + if (feof(fp) || ferror(fp)) + break; + errno = errno_save; + warn("%s: too few items assigned (iteration: %d)", + __func__, i); + } } fclose(fp); -- cgit v1.2.3