commit 82ab96153893cc232bebe37c3914b54a4722e3d6 from: Markus Uhlin date: Sat Aug 3 21:40:54 2024 UTC Return value checking commit - 93a68545fc69f41ba91b921de2179a4abb6fe351 commit + 82ab96153893cc232bebe37c3914b54a4722e3d6 blob - fe55052b4192e4f24d60367013a4e7f20df3ffce blob + 143ba3b2ae4cad32f1c7a5e0ef216a3451c28b92 --- FICS/gamedb.c +++ FICS/gamedb.c @@ -1268,14 +1268,27 @@ ReadV1GameFmt(game *g, FILE *fp, const char *file, int 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);