MOD aaa-12 解决json转换成结构体的时候,字符串可能越界的问题
SOL 解决json转换成结构体的时候,字符串可能越界的问题 修改人:zhangliang 检视人:zhangliang
This commit is contained in:
parent
5681bd1e57
commit
c705013df8
|
@ -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); \
|
||||
|
|
Loading…
Reference in New Issue