mirror of
https://github.com/DaveGamble/cJSON.git
synced 2023-08-10 21:13:26 +03:00
fix strlen(null)
When used in this way, it may cause errors : strlen(null) cJSON* json= cJSON_CreateObject(); json->type = cJSON_String; cJSON_SetValuestring(json,string);
This commit is contained in:
parent
b45f48e600
commit
860ed3a77c
9
cJSON.c
9
cJSON.c
@ -405,10 +405,13 @@ CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring)
|
|||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (strlen(valuestring) <= strlen(object->valuestring))
|
if (object->valuestring != NULL)
|
||||||
{
|
{
|
||||||
strcpy(object->valuestring, valuestring);
|
if (strlen(valuestring) <= strlen(object->valuestring))
|
||||||
return object->valuestring;
|
{
|
||||||
|
strcpy(object->valuestring, valuestring);
|
||||||
|
return object->valuestring;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
copy = (char*) cJSON_strdup((const unsigned char*)valuestring, &global_hooks);
|
copy = (char*) cJSON_strdup((const unsigned char*)valuestring, &global_hooks);
|
||||||
if (copy == NULL)
|
if (copy == NULL)
|
||||||
|
Loading…
Reference in New Issue
Block a user