fix invalid access when method_arg is void

This commit is contained in:
pikastech 2022-06-06 14:45:37 +08:00
parent 607591d78c
commit f888b32e92
5 changed files with 9 additions and 7 deletions

View File

@ -11,7 +11,7 @@
"program": "${workspaceFolder}/build/test/pikascript_test",
// "program": "${workspaceFolder}/build/boot/demo06-pikamain/pikascript_demo06-pikamain",
"args": [
// "--gtest_filter=parser.json_literal"
"--gtest_filter=module.cmodule_import"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",

View File

@ -29,8 +29,9 @@ TEST(module, cmodule_import) {
/* assert */
/* deinit */
EXPECT_STREQ("NameError: name 'TemplateDevice.qqee' is not defined\r\n",
log_buff[5]);
EXPECT_STREQ("NameError: name 'qqee' is not defined\r\n",
log_buff[2]);
EXPECT_STREQ("BEGIN\r\n", log_buff[3]);
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}

View File

@ -1,6 +1,6 @@
sh only_make.sh
if [ $# == 0 ] ; then
valgrind -s --track-origins=yes --leak-check=full --show-leak-kinds=all build/test/pikascript_test
valgrind -s --track-origins=yes --leak-check=full --show-leak-kinds=all --exit-on-first-error=yes build/test/pikascript_test
fi
if [ $# == 1 ] ; then

View File

@ -9,6 +9,9 @@ class BaseObj(TinyObj):
class pointer:
pass
class any:
pass
def print(val: any):
pass

View File

@ -354,14 +354,12 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self, VMState* vs, char* data) {
method_arg = obj_getMethodArg(vs->globals, methodPath);
}
/* assert method*/
if (NULL == method_arg) {
if (NULL == method_arg || ARG_TYPE_VOID == arg_getType(method_arg)) {
/* error, method no found */
VMState_setErrorCode(vs, 2);
__platform_printf("NameError: name '%s' is not defined\r\n", data);
goto exit;
}
sub_locals = New_PikaObj();
/* load args from vmState to sub_local->list */
arg_num_used = VMState_loadArgsFromMethodArg(