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
3
cJSON.c
3
cJSON.c
@ -405,11 +405,14 @@ CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring)
|
|||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
if (object->valuestring != NULL)
|
||||||
|
{
|
||||||
if (strlen(valuestring) <= strlen(object->valuestring))
|
if (strlen(valuestring) <= strlen(object->valuestring))
|
||||||
{
|
{
|
||||||
strcpy(object->valuestring, valuestring);
|
strcpy(object->valuestring, valuestring);
|
||||||
return object->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