diff --git a/src/game/script/routines_common.cpp b/src/game/script/routines_common.cpp index a2c3f19e..15fcfd48 100644 --- a/src/game/script/routines_common.cpp +++ b/src/game/script/routines_common.cpp @@ -79,7 +79,14 @@ Variable Routines::stringToFloat(const VariablesList &args, ExecutionContext &ct } Variable Routines::stringToInt(const VariablesList &args, ExecutionContext &ctx) { - return Variable::ofInt(stoi(getString(args, 0))); + int result = 0; + string number(getString(args, 0)); + + if (!number.empty()) { + result = stoi(number); + } + + return Variable::ofInt(result); } Variable Routines::turnsToSeconds(const VariablesList &args, ExecutionContext &ctx) { diff --git a/src/game/script/routines_strings.cpp b/src/game/script/routines_strings.cpp index 56727fed..be69ad9b 100644 --- a/src/game/script/routines_strings.cpp +++ b/src/game/script/routines_strings.cpp @@ -49,15 +49,27 @@ Variable Routines::getStringLowerCase(const VariablesList &args, ExecutionContex } Variable Routines::getStringRight(const VariablesList &args, ExecutionContext &ctx) { + string result; string str(getString(args, 0)); int count = getInt(args, 1); - return Variable::ofString(str.substr(str.length() - count, count)); + + if (str.size() >= count) { + result = str.substr(str.length() - count, count); + } + + return Variable::ofString(move(result)); } Variable Routines::getStringLeft(const VariablesList &args, ExecutionContext &ctx) { + string result; string str(getString(args, 0)); int count = getInt(args, 1); - return Variable::ofString(str.substr(0, count)); + + if (str.size() >= count) { + result = str.substr(0, count); + } + + return Variable::ofString(move(result)); } Variable Routines::insertString(const VariablesList &args, ExecutionContext &ctx) {