aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2024-05-04 16:59:45 +0200
committerMarkus Uhlin <markus@nifty-networks.net>2024-05-04 16:59:45 +0200
commit946ce55013060d66a0f2c4e609646fbfb3b760c6 (patch)
tree2a52b01e032b9355ab4412baf8a188204585370a
parent8ad06a6fa647500e1eefd703ef08a5c8990ccdbd (diff)
Revised get_empty_slot()
-rw-r--r--FICS/gamedb.c46
1 files changed, 29 insertions, 17 deletions
diff --git a/FICS/gamedb.c b/FICS/gamedb.c
index 444323c..8674393 100644
--- a/FICS/gamedb.c
+++ b/FICS/gamedb.c
@@ -66,24 +66,36 @@ PUBLIC char *rstr[] = {
PRIVATE char gameString[GAME_STRING_LEN];
-PRIVATE int get_empty_slot()
-/* this method is awful! how about allocation as we need it and freeing
- afterwards! */
+/*
+ * This method is awful! How about allocation as we need it and
+ * freeing afterwards!
+ */
+PRIVATE int
+get_empty_slot(void)
{
- int i;
-
- for (i = 0; i < g_num; i++) {
- if (garray[i].status == GAME_EMPTY)
- return i;
- }
- g_num++;
- if (!garray) {
- garray = (game *) rmalloc(sizeof(game) * g_num);
- } else {
- garray = (game *) rrealloc(garray, sizeof(game) * g_num);
- } /* yeah great, bet this causes lag! - DAV*/
- garray[g_num - 1].status = GAME_EMPTY;
- return g_num - 1;
+ for (int i = 0; i < g_num; i++) {
+ if (garray[i].status == GAME_EMPTY)
+ return i;
+ }
+
+ g_num++;
+
+ if (!garray) {
+ garray = reallocarray(NULL, sizeof(game), g_num);
+
+ if (garray == NULL)
+ err(1, "%s: reallocarray", __func__);
+ else
+ malloc_count++;
+ } else {
+ garray = reallocarray(garray, sizeof(game), g_num);
+
+ if (garray == NULL)
+ err(1, "%s: reallocarray", __func__);
+ } // Yeah great, bet this causes lag! - DAV
+
+ garray[g_num - 1].status = GAME_EMPTY;
+ return g_num - 1;
}
PUBLIC int