avoid core dump when not ':' found

This commit is contained in:
pikastech 2022-08-05 11:18:54 +08:00
parent 178353e259
commit 0c0d89231c
5 changed files with 48 additions and 3 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=VM.Run_add"
"--gtest_filter=pikaMain.dump_issue_12l3kjioa"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",

View File

@ -2512,3 +2512,38 @@ TEST(pikaMain, for_loop_issue_1b2a3f1bdf) {
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(pikaMain, syantex_issue123lkjxi) {
char* lines =
"if i < 3\n";
/* init */
pikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
obj_run(pikaMain, lines);
/* collect */
/* assert */
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(pikaMain, dump_issue_12l3kjioa) {
char* lines =
"if i = 1:\n"
" print('test')\n"
"\n"
;
/* init */
pikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
obj_run(pikaMain, lines);
/* collect */
/* assert */
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}

View File

@ -163,6 +163,7 @@ char* strsPopTokenWithSkip_byStr(Args* outBuffs,
}
char* strsGetCleanCmd(Args* outBuffs, char* cmd) {
pika_assert(cmd!=NULL);
int32_t size = strGetSize(cmd);
/* lexer may generate more chars than input */
char* strOut = args_getBuff(outBuffs, size * 2);
@ -1860,6 +1861,11 @@ AST* AST_parseLine(char* line, Stack* block_stack) {
}
block_matched:
if (NULL == stmt){
AST_deinit(ast);
ast = NULL;
goto exit;
}
stmt = strsGetCleanCmd(&buffs, stmt);
ast = AST_parseStmt(ast, stmt);
goto exit;

View File

@ -1167,7 +1167,10 @@ static Arg* VM_instruction_handler_JEZ(PikaObj* self,
int jmp_expect = fast_atoi(data);
arg_newReg(pika_assertArg_reg, PIKA_ARG_BUFF_SIZE);
Arg* pika_assertArg = stack_popArg(&(vs->stack), &pika_assertArg_reg);
int pika_assert = arg_getInt(pika_assertArg);
int pika_assert = 0;
if (NULL != pika_assertArg) {
pika_assert = arg_getInt(pika_assertArg);
}
arg_deinit(pika_assertArg);
vs->ireg[thisBlockDeepth] = !pika_assert;

View File

@ -269,6 +269,7 @@ Arg* arg_setStr(Arg* self, char* name, char* string) {
}
int64_t arg_getInt(Arg* self) {
pika_assert(NULL!=self);
if (NULL == arg_getContent(self)) {
return -999999;
}
@ -327,7 +328,7 @@ Arg* arg_copy_noalloc(Arg* arg_src, Arg* arg_dict) {
if (NULL == arg_src) {
return NULL;
}
if (NULL == arg_dict){
if (NULL == arg_dict) {
return arg_copy(arg_src);
}
/* size is too big to be copied by noalloc */