From cd07ae1a3a20716ece3327c6b76ed96ccb3eabe9 Mon Sep 17 00:00:00 2001 From: cloudwalk Date: Mon, 28 Sep 2020 14:48:42 +0000 Subject: [PATCH] cmd: Update defer command to allocate the same as Cmd_ParseText git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12954 d7cf8633-e32d-0410-b094-e92efae38249 --- cmd.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/cmd.c b/cmd.c index 6ef52f52..aa6eea83 100644 --- a/cmd.c +++ b/cmd.c @@ -109,14 +109,19 @@ static void Cmd_Defer_f (cmd_state_t *cmd) { const char *text = Cmd_Argv(cmd, 2); current = Cbuf_LinkGet(cbuf, NULL); - current->size = strlen(text); + current->length = strlen(text); current->source = cmd; current->delay = atof(Cmd_Argv(cmd, 1)); - memcpy(current->text, text, current->size + 1); + if(current->size < current->length) + { + current->text = (char *)Mem_Realloc(cbuf_mempool, current->text, current->length + 1); + current->size = current->length; + } - List_Move_Tail(¤t->list, &cbuf->deferred); + strlcpy(current->text, text, current->length + 1); + List_Move_Tail(¤t->list, &cbuf->deferred); } else { @@ -382,7 +387,7 @@ void Cbuf_InsertText (cmd_state_t *cmd, const char *text) Cbuf_Lock(cbuf); // we need to memmove the existing text and stuff this in before it... - if (cbuf->size + l >= (size_t)cbuf->maxsize) + if (cbuf->size + l >= cbuf->maxsize) Con_Print("Cbuf_InsertText: overflow\n"); else { -- 2.39.2