From 19a0060d874682443467614070a3a03e0d5f890f Mon Sep 17 00:00:00 2001 From: divverent Date: Sun, 16 Mar 2008 17:31:32 +0000 Subject: [PATCH] fix cmd again (fix by Blub and me) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8212 d7cf8633-e32d-0410-b094-e92efae38249 --- cmd.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/cmd.c b/cmd.c index 4e1fb729..b515dbb9 100644 --- a/cmd.c +++ b/cmd.c @@ -161,7 +161,9 @@ void Cbuf_Execute (void) { if (text[i] == '"') quotes ^= 1; - if (text[i] == '\\' && (text[i+1] == '"' || text[i+1] == '\\')) + // make sure i doesn't get > cursize which causes a negative + // size in memmove, which is fatal --blub + if (i < (cmd_text.cursize-1) && (text[i] == '\\' && (text[i+1] == '"' || text[i+1] == '\\'))) i++; if ( !quotes && text[i] == ';') break; // don't break if inside a quoted string @@ -169,13 +171,17 @@ void Cbuf_Execute (void) break; } - /* should never happen + // better than CRASHING on overlong input lines that may SOMEHOW enter the buffer if(i >= MAX_INPUTLINE) - i = MAX_INPUTLINE - 1; - */ - - memcpy (line, text, i); - line[i] = 0; + { + Con_Printf("Warning: console input buffer had an overlong line. Ignored.\n"); + line[0] = 0; + } + else + { + memcpy (line, text, i); + line[i] = 0; + } // delete the text from the command buffer and move remaining commands down // this is necessary because commands (exec, alias) can insert data at the -- 2.39.2