aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2024-08-03 21:58:53 +0200
committerMarkus Uhlin <markus@nifty-networks.net>2024-08-03 21:58:53 +0200
commita22686dfd2158200e4615d5c630c23567246220b (patch)
treec465b74bd55d9c04fb810083c856a742b10b3a5f
parentbf864d0b27a218c34d92b54a63a9bd8dbffca8f4 (diff)
Return value checking
-rw-r--r--FICS/gamedb.c22
1 files changed, 16 insertions, 6 deletions
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);