void TestSegFunction(void)
{
int i = 0;
char *str = "\"{\"loop_number\":1}\""; // line 410
char *str = "{\"loop_number\":1}"; // line 411
json_object *pstObj = NULL;
json_object *sonPstObj = NULL;
pstObj = json_tokener_parse(str); // line 414
if (NULL == pstObj)
{
printf("%s : json_tokener_parse failed.\n", __FUNCTION__);
}
else
{
json_object_object_foreach(pstObj, key1, val1)
{
if (0 == strcmp(key1, LOOP_NUMBER))
{
i = json_object_get_int(val1);
printf("i = %d\n", i);
}
}
}
}
As shown in lines 410 and 411, if 410 lines of code are used, there will be a segment error in 414 lines of function calls. If 411 lines of code are used, there will be no error in 414 lines, because this function is called by others, and they may enter an error string. I don't want to see the segment error to stop the program. Is there any way to avoid this kind of paragraph error?