From 3b57ae2a903de4de954f59dbbcca477ee3bdac96 Mon Sep 17 00:00:00 2001 From: Andrei Drexler Date: Sun, 4 Aug 2024 10:07:10 +0200 Subject: [PATCH] Copy tab completion type strings to hunk instead of assuming they're all literals --- Quake/console.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Quake/console.c b/Quake/console.c index e7eccb87e..ce7fa9a6c 100644 --- a/Quake/console.c +++ b/Quake/console.c @@ -1598,7 +1598,7 @@ void Con_AddToTabList (const char *name, const char *partial, const char *type) tab_t *t,*insert; char *i_bash, *i_bash2; const char *i_name, *i_name2; - int len, mark; + int namelen, typelen, mark; if (!Con_Match (name, partial)) return; @@ -1638,11 +1638,16 @@ void Con_AddToTabList (const char *name, const char *partial, const char *type) } mark = Hunk_LowMark (); - len = strlen (name); - t = (tab_t *) Hunk_AllocName (sizeof (tab_t) + len + 1, "tablist"); - memcpy (t + 1, name, len + 1); + namelen = (int) strlen (name) + 1; + typelen = type ? (int) strlen (type) + 1 : 0; + t = (tab_t *) Hunk_AllocName (sizeof (tab_t) + namelen + typelen, "tablist"); t->name = (const char *) (t + 1); - t->type = type; + memcpy ((char *) t->name, name, namelen); + if (type) + { + t->type = t->name + namelen; + memcpy ((char *) t->type, type, typelen); + } t->count = 1; if (!tablist) //create list