aboutsummaryrefslogtreecommitdiffstats
path: root/FICS
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2024-08-03 23:40:54 +0200
committerMarkus Uhlin <markus@nifty-networks.net>2024-08-03 23:40:54 +0200
commit82ab96153893cc232bebe37c3914b54a4722e3d6 (patch)
treebbbf6ca807b590d01effe6ef6951b44a8f89ea98 /FICS
parent93a68545fc69f41ba91b921de2179a4abb6fe351 (diff)
Return value checking
Diffstat (limited to 'FICS')
-rw-r--r--FICS/gamedb.c25
1 files changed, 19 insertions, 6 deletions
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);