From a22686dfd2158200e4615d5c630c23567246220b Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Sat, 3 Aug 2024 21:58:53 +0200 Subject: Return value checking --- FICS/gamedb.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'FICS') diff --git a/FICS/gamedb.c b/FICS/gamedb.c index 524bd5a..d3fff96 100644 --- a/FICS/gamedb.c +++ b/FICS/gamedb.c @@ -1233,21 +1233,31 @@ ReadV1Moves(game *g, FILE *fp) PRIVATE int ReadV1GameFmt(game *g, FILE *fp, const char *file, int version) { - long int lval; + int ret[3]; + long int lval; - fscanf(fp, "%s %s", g->white_name, g->black_name); - fscanf(fp, "%d %d", &g->white_rating, &g->black_rating); - fscanf(fp, "%d %d %d %d", + ret[0] = fscanf(fp, "%s %s", g->white_name, g->black_name); + ret[1] = fscanf(fp, "%d %d", &g->white_rating, &g->black_rating); + ret[2] = fscanf(fp, "%d %d %d %d", &g->wInitTime, &g->wIncrement, &g->bInitTime, &g->bIncrement); + if (ret[0] != 2 || + ret[1] != 2 || + ret[2] != 4) { + warnx("%s: fscanf error: %s", __func__, file); + return -1; + } if (version < 3 && !g->bInitTime) g->bInitTime = g->wInitTime; - fscanf(fp, "%ld", &lval); - g->timeOfStart = lval; + if (fscanf(fp, "%ld", &lval) != 1) { + warnx("%s: %s: failed to get time of start", __func__, file); + return -1; + } else + g->timeOfStart = lval; fscanf(fp, "%d %d", &g->wTime, &g->bTime); -- cgit v1.2.3