From 82ab96153893cc232bebe37c3914b54a4722e3d6 Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Sat, 3 Aug 2024 23:40:54 +0200 Subject: Return value checking --- FICS/gamedb.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'FICS') diff --git a/FICS/gamedb.c b/FICS/gamedb.c index fe55052..143ba3b 100644 --- a/FICS/gamedb.c +++ b/FICS/gamedb.c @@ -1268,14 +1268,27 @@ ReadV1GameFmt(game *g, FILE *fp, const char *file, int version) return -1; } - if (version > 1) - fscanf(fp, "%d %d", &g->result, &g->winner); - else - fscanf(fp, "%d", &g->result); + if (version > 1) { + if (fscanf(fp, "%d %d", &g->result, &g->winner) != 2) { + warnx("%s: %s: failed to get 'result' nor 'winner'", + __func__, file); + return -1; + } + } else { + if (fscanf(fp, "%d", &g->result) != 1) { + warnx("%s: %s: failed to get 'result'", + __func__, file); + return -1; + } + } - fscanf(fp, "%d %d %d %d", &g->private, &g->type, &g->rated, + ret[0] = fscanf(fp, "%d %d %d %d", &g->private, &g->type, &g->rated, &g->clockStopped); - fscanf(fp, "%d", &g->numHalfMoves); + ret[1] = fscanf(fp, "%d", &g->numHalfMoves); + if (ret[0] != 4 || ret[1] != 1) { + warnx("%s: fscanf error: %s", __func__, file); + return -1; + } if (ReadV1Moves(g, fp) != 0) { warnx("%s: failed to read moves: %s", __func__, file); -- cgit v1.2.3