Fix CTD in danm14aa

This commit is contained in:
Vsevolod Kremianskii 2021-04-20 10:25:05 +07:00
parent 31290dc7d0
commit 874a4006b6
2 changed files with 22 additions and 3 deletions

View file

@ -79,7 +79,14 @@ Variable Routines::stringToFloat(const VariablesList &args, ExecutionContext &ct
} }
Variable Routines::stringToInt(const VariablesList &args, ExecutionContext &ctx) { 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) { Variable Routines::turnsToSeconds(const VariablesList &args, ExecutionContext &ctx) {

View file

@ -49,15 +49,27 @@ Variable Routines::getStringLowerCase(const VariablesList &args, ExecutionContex
} }
Variable Routines::getStringRight(const VariablesList &args, ExecutionContext &ctx) { Variable Routines::getStringRight(const VariablesList &args, ExecutionContext &ctx) {
string result;
string str(getString(args, 0)); string str(getString(args, 0));
int count = getInt(args, 1); 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) { Variable Routines::getStringLeft(const VariablesList &args, ExecutionContext &ctx) {
string result;
string str(getString(args, 0)); string str(getString(args, 0));
int count = getInt(args, 1); 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) { Variable Routines::insertString(const VariablesList &args, ExecutionContext &ctx) {