From c4433a3c7542e2bb0dfe00c3438c29178e8319cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E6=88=98?= <40414978+PatriceJiang@users.noreply.github.com> Date: Sat, 10 Oct 2020 16:28:10 +0800 Subject: [PATCH] fix outof range error (#2885) --- .../templates/struct_constructor.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/native/tools/bindings-generator/targets/spidermonkey/templates/struct_constructor.c b/native/tools/bindings-generator/targets/spidermonkey/templates/struct_constructor.c index 37d7c3ba9d..359bf737c9 100644 --- a/native/tools/bindings-generator/targets/spidermonkey/templates/struct_constructor.c +++ b/native/tools/bindings-generator/targets/spidermonkey/templates/struct_constructor.c @@ -98,13 +98,17 @@ static bool ${struct_constructor_name}(se::State& s) #else ${field_type} arg${arg_idx}; #end if - if (!args[${arg_idx}].isUndefined()) { - $conv_text; - #if "seval_to_reference" in $conv_text_array[$arg_idx] - cobj->${field.name} = *arg${arg_idx}; - #else - cobj->${field.name} = arg${arg_idx}; - #end if + if (argc > ${arg_idx}) { + if (!args[${arg_idx}].isUndefined()) { + $conv_text; + #if "seval_to_reference" in $conv_text_array[$arg_idx] + cobj->${field.name} = *arg${arg_idx}; + #else + cobj->${field.name} = arg${arg_idx}; + #end if + } else { + SE_REPORT_ERROR("Argument %d is undefined", ${arg_idx}); + } } #set $arg_idx = $arg_idx + 1 #end for