MOD aaa-12 解决json转换成结构体的时候,字符串可能越界的问题

SOL  解决json转换成结构体的时候,字符串可能越界的问题
修改人:zhangliang
检视人:zhangliang
This commit is contained in:
zhanglianghy 2019-07-18 11:04:11 +08:00
parent 5681bd1e57
commit c705013df8
1 changed files with 2 additions and 1 deletions

View File

@ -52,7 +52,8 @@ typedef struct {
#define S2J_STRUCT_GET_STRING_ELEMENT_N(to_struct, from_json, _element, n) \
json_temp = cJSON_GetObjectItem(from_json, #_element); \
if (json_temp && n > 1) strncpy((to_struct)->_element, json_temp->valuestring, n-1);
if (json_temp && json_temp->valuestring && n > 1)\
strncpy((to_struct)->_element, json_temp->valuestring, n-1);
#define S2J_STRUCT_GET_double_ELEMENT(to_struct, from_json, _element) \
json_temp = cJSON_GetObjectItem(from_json, #_element); \