aboutsummaryrefslogtreecommitdiffstats
path: root/FICS/ratings.c
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2024-07-07 15:26:44 +0200
committerMarkus Uhlin <markus@nifty-networks.net>2024-07-07 15:26:44 +0200
commit371c0f00545b70b67043765677a83a4bfa0bf827 (patch)
tree5f3054b96848c13e386a2ad551925dd65f2d8a51 /FICS/ratings.c
parent41a92d80a86dc2f2639d2374b50a0326a9b086ad (diff)
Check the retval of fscanf()
Diffstat (limited to 'FICS/ratings.c')
-rw-r--r--FICS/ratings.c13
1 files changed, 12 insertions, 1 deletions
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);