错误日志如下:
Exception Entry--->>>
mcause 38000005, mepc 2302934c, mtval 65746194
=== backtrace_trap start ===
-f -p 2302934c 23013b02 23013b02 2300b70e 23004662 2301367e 2302edf4
backtrace_trap: reached task deathbed!!!
=== backtrace_trap end ===
通过map文件定位是
.text.get_object_item
0x0000000023029328 0x90 prebuild/lib/cjson.a(cJSON.o)
.text.add_item_to_array
0x00000000230293b8 0x40 prebuild/lib/cjson.a(cJSON.o)
.text.print_string_ptr
0x00000000230293f8 0x1ac prebuild/lib/cjson.a(cJSON.o)
代码如下
int ret = -1 ;
char *payload = NULL;
cJSON *item;
cJSON *root;
char *str = (char*)aos_malloc(4);
root = cJSON_CreateObject();
if(root == NULL)
{
return;
}
sprintf(str,"%d",led.power);
cJSON_AddStringToObject(root,PROPERTY_POWERSTATE,str);
payload = cJSON_PrintUnformatted(root);
if(payload == NULL)
{
goto exit;
}
printf("--------->%s\n",payload);
cloud_packet_send(0,MSG_TYPE_REPORT,payload,strlen(payload));
hal_free(payload);
hal_free(str);
exit:;
cJSON_Delete(root);
hal_free(root);
char *str = (char*)aos_malloc(4);
如果换成char *str
也会导致程序崩溃
非常简单的代码,居然会出错,目前还没搞清楚出错的原因,麻烦帮忙看下 ,感谢!