From a2b0efbfe40485585f29017f2d3d865546fb0950 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Mon, 25 Jan 2016 09:25:34 +0100 Subject: [PATCH] Fix for json_node_deep_copy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It didn’t properly initialized the copied nodes. --- src/utils.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/utils.c b/src/utils.c index 36299da..ecda5dc 100644 --- a/src/utils.c +++ b/src/utils.c @@ -112,18 +112,30 @@ _json_node_deep_copy(const JsonNode *node) switch (JSON_NODE_TYPE((JsonNode *)node)) { case JSON_NODE_OBJECT: + { + JsonObject *new_obj = json_object_new(); + json_object_foreach_member(json_node_get_object((JsonNode *)node), (JsonObjectForeach)deep_copy_object, - json_node_get_object(ret)); + new_obj); + + json_node_set_object(ret, new_obj); break; + } case JSON_NODE_ARRAY: + { + JsonArray *new_ary = json_array_new(); + json_array_foreach_element(json_node_get_array((JsonNode *)node), - (JsonArrayForeach)deep_copy_array, - json_node_get_array(ret)); + (JsonArrayForeach)deep_copy_array, + new_ary); + + json_node_set_array(ret, new_ary); break; + } case JSON_NODE_VALUE: {