summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2016-11-27 14:15:17 +0100
committerGravatar Nikias Bassen2016-11-27 14:15:17 +0100
commit950b6ddc3e503c4e1e3cb5d7813cdd9b41849cbc (patch)
tree42c8640c869b6a486490807ba994870ed64650e6 /src
parent75140cb96acb6ef1d0482aa48d90275009ecb9ef (diff)
downloadlibplist-950b6ddc3e503c4e1e3cb5d7813cdd9b41849cbc.tar.gz
libplist-950b6ddc3e503c4e1e3cb5d7813cdd9b41849cbc.tar.bz2
plist_copy: Duplicate hash tables when copying PLIST_DICT nodes
Diffstat (limited to 'src')
-rw-r--r--src/plist.c20
1 files 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);