Merge pull request #16173 from vnen/gdscript-arguments

Add argument count check for some GDScript functions
This commit is contained in:
Rémi Verschelde 2018-02-19 21:35:53 +01:00 committed by GitHub
commit aeed774fef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View file

@ -358,13 +358,16 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_
r_ret = Math::dectime((double)*p_args[0], (double)*p_args[1], (double)*p_args[2]); r_ret = Math::dectime((double)*p_args[0], (double)*p_args[1], (double)*p_args[2]);
} break; } break;
case MATH_RANDOMIZE: { case MATH_RANDOMIZE: {
VALIDATE_ARG_COUNT(0);
Math::randomize(); Math::randomize();
r_ret = Variant(); r_ret = Variant();
} break; } break;
case MATH_RAND: { case MATH_RAND: {
VALIDATE_ARG_COUNT(0);
r_ret = Math::rand(); r_ret = Math::rand();
} break; } break;
case MATH_RANDF: { case MATH_RANDF: {
VALIDATE_ARG_COUNT(0);
r_ret = Math::randf(); r_ret = Math::randf();
} break; } break;
case MATH_RANDOM: { case MATH_RANDOM: {
@ -593,7 +596,13 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_
r_ret = String(result); r_ret = String(result);
} break; } break;
case TEXT_STR: { case TEXT_STR: {
if (p_arg_count < 1) {
r_error.error = Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
r_error.argument = 1;
r_ret = Variant();
return;
}
String str; String str;
for (int i = 0; i < p_arg_count; i++) { for (int i = 0; i < p_arg_count; i++) {
@ -1180,6 +1189,7 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_
} break; } break;
case PRINT_STACK: { case PRINT_STACK: {
VALIDATE_ARG_COUNT(0);
ScriptLanguage *script = GDScriptLanguage::get_singleton(); ScriptLanguage *script = GDScriptLanguage::get_singleton();
for (int i = 0; i < script->debug_get_stack_level_count(); i++) { for (int i = 0; i < script->debug_get_stack_level_count(); i++) {

View file

@ -1516,11 +1516,11 @@ GDScriptParser::Node *GDScriptParser::_reduce_expression(Node *p_node, bool p_to
String errwhere; String errwhere;
if (op->arguments[0]->type == Node::TYPE_TYPE) { if (op->arguments[0]->type == Node::TYPE_TYPE) {
TypeNode *tn = static_cast<TypeNode *>(op->arguments[0]); TypeNode *tn = static_cast<TypeNode *>(op->arguments[0]);
errwhere = "'" + Variant::get_type_name(tn->vtype) + "'' constructor"; errwhere = "'" + Variant::get_type_name(tn->vtype) + "' constructor";
} else { } else {
GDScriptFunctions::Function func = static_cast<BuiltInFunctionNode *>(op->arguments[0])->function; GDScriptFunctions::Function func = static_cast<BuiltInFunctionNode *>(op->arguments[0])->function;
errwhere = String("'") + GDScriptFunctions::get_func_name(func) + "'' intrinsic function"; errwhere = String("'") + GDScriptFunctions::get_func_name(func) + "' intrinsic function";
} }
switch (ce.error) { switch (ce.error) {