From 950b6ddc3e503c4e1e3cb5d7813cdd9b41849cbc Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Sun, 27 Nov 2016 14:15:17 +0100 Subject: plist_copy: Duplicate hash tables when copying PLIST_DICT nodes --- src/plist.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/plist.c b/src/plist.c index 6a267eb..8c2866d 100644 --- a/src/plist.c +++ b/src/plist.c @@ -325,10 +325,7 @@ static void plist_copy_node(node_t *node, void *parent_node_ptr) memcpy(newdata, data, sizeof(struct plist_data_s)); node_type = plist_get_node_type(node); - if (node_type == PLIST_DATA || node_type == PLIST_STRING || node_type == PLIST_KEY) - { - switch (node_type) - { + switch (node_type) { case PLIST_DATA: newdata->buff = (uint8_t *) malloc(data->length); memcpy(newdata->buff, data->buff, data->length); @@ -337,9 +334,22 @@ static void plist_copy_node(node_t *node, void *parent_node_ptr) case PLIST_STRING: newdata->strval = strdup((char *) data->strval); break; + case PLIST_DICT: + if (data->hashtable) { + hashtable_t* ht = hash_table_new(dict_key_hash, dict_key_compare, NULL); + assert(ht); + plist_t current = NULL; + for (current = (plist_t)node_first_child(node); + ht && current; + current = (plist_t)node_next_sibling(node_next_sibling(current))) + { + hash_table_insert(ht, ((node_t*)current)->data, node_next_sibling(current)); + } + newdata->hashtable = ht; + } + break; default: break; - } } newnode = plist_new_node(newdata); -- cgit v1.1-32-gdbae