Fix const-correctness in script DoCommand string validation

See: 665e3c1f
This commit is contained in:
Jonathan G Rennison
2021-11-01 18:16:46 +00:00
parent 0563c0e308
commit c6f0559ad4

View File

@@ -15,6 +15,7 @@
#include "../../network/network.h" #include "../../network/network.h"
#include "../../genworld.h" #include "../../genworld.h"
#include "../../string_func.h" #include "../../string_func.h"
#include "../../string_func_extra.h"
#include "../../strings_func.h" #include "../../strings_func.h"
#include "../../scope_info.h" #include "../../scope_info.h"
#include "../../map_func.h" #include "../../map_func.h"
@@ -313,10 +314,13 @@ ScriptObject::ActiveInstance::~ActiveInstance()
return false; return false;
} }
std::string text_validated;
if (binary_length == 0 && !StrEmpty(text) && (GetCommandFlags(cmd) & CMD_STR_CTRL) == 0) { if (binary_length == 0 && !StrEmpty(text) && (GetCommandFlags(cmd) & CMD_STR_CTRL) == 0) {
/* The string must be valid, i.e. not contain special codes. Since some /* The string must be valid, i.e. not contain special codes. Since some
* can be made with GSText, make sure the control codes are removed. */ * can be made with GSText, make sure the control codes are removed. */
::StrMakeValidInPlace(const_cast<char *>(text), text + strlen(text), SVS_NONE); text_validated = text;
::StrMakeValidInPlace(text_validated, SVS_NONE);
text = text_validated.c_str();
} }
/* Set the default callback to return a true/false result of the DoCommand */ /* Set the default callback to return a true/false result of the DoCommand */