From 0d23e46ce6891f2d836b9b7f2bf7d40d5d5eabfd Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Sun, 5 May 2024 04:08:43 +0200 Subject: Added usage of reallocarray() --- FICS/gameproc.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/FICS/gameproc.c b/FICS/gameproc.c index 10531c6..f53518c 100644 --- a/FICS/gameproc.c +++ b/FICS/gameproc.c @@ -34,6 +34,8 @@ #include "stdinclude.h" #include "common.h" +#include + #include "command.h" #include "comproc.h" #include "config.h" @@ -451,20 +453,25 @@ process_move(int p, char *command) garray[g].numHalfMoves++; if (garray[g].numHalfMoves > garray[g].examMoveListSize) { - size_t size; - garray[g].examMoveListSize += 20; // Allocate 20 // moves at a // time - size = (sizeof(move_t) * garray[g].examMoveListSize); - if (!garray[g].examMoveList) { - garray[g].examMoveList = rmalloc(size); + garray[g].examMoveList = + reallocarray(NULL, + sizeof(move_t), + garray[g].examMoveListSize); + if (garray[g].examMoveList == NULL) + err(1, "%s: reallocarray", __func__); + else + malloc_count++; } else { garray[g].examMoveList = - rrealloc(garray[g].examMoveList, - (sizeof(move_t) * - garray[g].examMoveListSize)); + reallocarray(garray[g].examMoveList, + sizeof(move_t), + garray[g].examMoveListSize); + if (garray[g].examMoveList == NULL) + err(1, "%s: reallocarray", __func__); } } -- cgit v1.2.3