From 7dd51d6d1c2f1f425b529ed3742c342d032a4255 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Thu, 22 Dec 2016 11:00:20 +0200 Subject: [PATCH] Fixed infinite execution of error CCMD https://forum.zdoom.org/viewtopic.php?t=54659 --- src/c_console.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/c_console.cpp b/src/c_console.cpp index 691c4a3ca..0a324eb8f 100644 --- a/src/c_console.cpp +++ b/src/c_console.cpp @@ -1523,8 +1523,6 @@ static bool C_HandleKey (event_t *ev, FCommandBuffer &buffer) buffer.Text.StripLeftRight(); Printf(127, TEXTCOLOR_WHITE "]%s\n", buffer.Text.GetChars()); - AddCommandString(buffer.Text.LockBuffer()); - buffer.Text.UnlockBuffer(); if (buffer.Text.Len() == 0) { @@ -1568,7 +1566,21 @@ static bool C_HandleKey (event_t *ev, FCommandBuffer &buffer) } } HistPos = NULL; - buffer.SetString(""); + { + // Work with a copy of command to avoid side effects caused by + // exception raised during execution, like with 'error' CCMD. + // It's problematic to maintain FString's lock symmetry. + static TArray command; + const size_t length = buffer.Text.Len(); + + command.Resize(length + 1); + memcpy(&command[0], buffer.Text.GetChars(), length); + command[length] = '\0'; + + buffer.SetString(""); + + AddCommandString(&command[0]); + } TabbedLast = false; TabbedList = false; break;