From 7492fd875d455f0e69bdf95d33ea07d3b52bbada Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sat, 27 Mar 2021 08:08:59 +0000 Subject: [PATCH] map list/little code changes proposal. --- src/client/menu/menu.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/client/menu/menu.c b/src/client/menu/menu.c index 217d3699..270be5f7 100644 --- a/src/client/menu/menu.c +++ b/src/client/menu/menu.c @@ -3331,6 +3331,7 @@ StartServer_MenuInit(void) if (mapnames == NULL) { int i, length; + size_t nummapslen; nummaps = 0; s_startmap_list.curvalue = 0; @@ -3359,11 +3360,12 @@ StartServer_MenuInit(void) Com_Error(ERR_DROP, "no maps in maps.lst\n"); } - mapnames = malloc(sizeof(char *) * (nummaps + 1)); + nummapslen = sizeof(char *) * (nummaps + 1); + mapnames = malloc(nummapslen); - YQ2_COM_CHECK_OOM(mapnames, "malloc(sizeof(char *) * (nummaps + 1))", sizeof(char *) * (nummaps + 1)) + YQ2_COM_CHECK_OOM(mapnames, "malloc(sizeof(char *) * (nummaps + 1))", nummapslen) - memset(mapnames, 0, sizeof(char *) * (nummaps + 1)); + memset(mapnames, 0, nummapslen); s = buffer; @@ -3385,10 +3387,8 @@ StartServer_MenuInit(void) strcpy(longname, COM_Parse(&s)); Com_sprintf(scratch, sizeof(scratch), "%s\n%s", longname, shortname); - mapnames[i] = malloc(strlen(scratch) + 1); - YQ2_COM_CHECK_OOM(mapnames, "malloc()", strlen(scratch)+1) - - strcpy(mapnames[i], scratch); + mapnames[i] = strdup(scratch); + YQ2_COM_CHECK_OOM(mapnames[i], "strdup(scratch)", strlen(scratch)+1) } mapnames[nummaps] = 0;