mirror of
https://github.com/DaveGamble/cJSON.git
synced 2024-12-26 21:04:24 +08:00
fix: add allocate check for replace_item_in_object (#675)
Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
This commit is contained in:
parent
a6424b85dd
commit
b45f48e600
5
cJSON.c
5
cJSON.c
@ -2361,6 +2361,11 @@ static cJSON_bool replace_item_in_object(cJSON *object, const char *string, cJSO
|
|||||||
cJSON_free(replacement->string);
|
cJSON_free(replacement->string);
|
||||||
}
|
}
|
||||||
replacement->string = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks);
|
replacement->string = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks);
|
||||||
|
if (replacement->string == NULL)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
replacement->type &= ~cJSON_StringIsConst;
|
replacement->type &= ~cJSON_StringIsConst;
|
||||||
|
|
||||||
return cJSON_ReplaceItemViaPointer(object, get_object_item(object, string, case_sensitive), replacement);
|
return cJSON_ReplaceItemViaPointer(object, get_object_item(object, string, case_sensitive), replacement);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user