Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion cJSON_Utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1335,8 +1335,20 @@ static cJSON *merge_patch(cJSON *target, const cJSON * const patch, const cJSON_

if (!cJSON_IsObject(target))
{
/* The patch may be part of target: deleting target would free it.
* Work from a copy, as for non-object patches above. */
cJSON *patch_copy = cJSON_Duplicate(patch, 1);
cJSON *result = cJSON_CreateObject();
if ((patch_copy == NULL) || (result == NULL))
{
cJSON_Delete(patch_copy);
cJSON_Delete(result);
return NULL;
}
cJSON_Delete(target);
target = cJSON_CreateObject();
result = merge_patch(result, patch_copy, case_sensitive);
cJSON_Delete(patch_copy);
return result;
}

patch_child = patch->child;
Expand Down