From 106483f895e528fb969ff84433c33ecfa74eb45c Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Sat, 4 May 2024 12:27:38 +0200 Subject: Revised ReadV1Moves() --- FICS/gamedb.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'FICS') diff --git a/FICS/gamedb.c b/FICS/gamedb.c index fb788d8..3f7e64e 100644 --- a/FICS/gamedb.c +++ b/FICS/gamedb.c @@ -1001,16 +1001,21 @@ ReadOneV1Move(FILE *fp, move_t *m) strcat(m->algString, "+"); } -int ReadV1Moves(game *g, FILE * fp) +int +ReadV1Moves(game *g, FILE *fp) { - int i; + g->moveListSize = g->numHalfMoves; + g->moveList = reallocarray(NULL, sizeof(move_t), g->moveListSize); - g->moveListSize = g->numHalfMoves; - g->moveList = (move_t *) rmalloc(sizeof(move_t) * g->moveListSize); - for (i = 0; i < g->numHalfMoves; i++) { - ReadOneV1Move(fp, &g->moveList[i]); - } - return 0; + if (g->moveList == NULL) + err(1, "%s: reallocarray", __func__); + else + malloc_count++; + + for (int i = 0; i < g->numHalfMoves; i++) + ReadOneV1Move(fp, &g->moveList[i]); + + return 0; } int -- cgit v1.2.3