Fixed a bug where help("modules") crashed when no lib was loaded

This commit is contained in:
dreamcmi 2023-05-12 00:24:40 +08:00
parent fa5ea67ba8
commit cefa730d35
2 changed files with 20 additions and 0 deletions

View File

@ -2427,6 +2427,10 @@ PikaObj* obj_linkLibrary(PikaObj* self, uint8_t* library_bytes) {
void obj_printModules(PikaObj* self) {
LibObj* lib = obj_getObj(self, "@lib");
if (lib == NULL) {
pika_platform_printf("Error: Not found LibObj, please execute obj_linkLibrary()\r\n");
return;
}
pika_platform_printf(arg_getStr((Arg*)g_PikaObjState.helpModulesCmodule));
LibObj_printModules(lib);
}

View File

@ -3054,4 +3054,20 @@ TEST(pikaMain, _obj_set_str_null) {
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(pikaMain, shell_nolib_print_help) {
char lines[] = {"help(\"modules\")\n"};
/* init */
g_PikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
for (size_t i = 0; i < strGetSize(lines); i++) {
obj_runChar(pikaMain, lines[i]);
}
/* assert */
EXPECT_STREQ(log_buff[1], "Error: Not found LibObj, please execute obj_linkLibrary()\r\n");
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST_END