summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2012-04-24 01:18:46 +0200
committerGravatar Nikias Bassen2012-04-24 01:18:46 +0200
commit728bb0de241ed6fa8694ad68c71287acc8af4241 (patch)
treee7d5917ec6b85b45180d8d3c057ed84f79baeb29 /src
parent6697e4927883843e1bd537d778fc58bebd9a0b4e (diff)
downloadlibplist-728bb0de241ed6fa8694ad68c71287acc8af4241.tar.gz
libplist-728bb0de241ed6fa8694ad68c71287acc8af4241.tar.bz2
fix plist_dict_set_item() and plist_array_set_item()
Diffstat (limited to 'src')
-rw-r--r--src/plist.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/plist.c b/src/plist.c
index 6ee54cd..2b31fdd 100644
--- a/src/plist.c
+++ b/src/plist.c
@@ -67,10 +67,10 @@ static void plist_free_data(plist_data_t data)
}
}
-static void plist_free_node(node_t* node)
+static int plist_free_node(node_t* node)
{
plist_data_t data = NULL;
- node_detach(node->parent, node);
+ int index = node_detach(node->parent, node);
data = plist_get_data(node);
plist_free_data(data);
node->data = NULL;
@@ -83,6 +83,8 @@ static void plist_free_node(node_t* node)
node_iterator_destroy(ni);
node_destroy(node);
+
+ return index;
}
plist_t plist_new_dict(void)
@@ -264,9 +266,12 @@ void plist_array_set_item(plist_t node, plist_t item, uint32_t n)
plist_t old_item = plist_array_get_item(node, n);
if (old_item)
{
- plist_free_node(old_item);
- old_item = NULL;
- plist_copy_node(item, &old_item);
+ int idx = plist_free_node(old_item);
+ if (idx < 0) {
+ node_attach(node, item);
+ } else {
+ node_insert(node, idx, item);
+ }
}
}
return;
@@ -393,12 +398,15 @@ void plist_dict_set_item(plist_t node, const char* key, plist_t item)
{
if (node && PLIST_DICT == plist_get_node_type(node))
{
- plist_t old_item = plist_dict_get_item(node, key);
+ node_t* old_item = plist_dict_get_item(node, key);
if (old_item)
{
- plist_free_node(old_item);
- old_item = NULL;
- plist_copy_node(item, &old_item);
+ int idx = plist_free_node(old_item);
+ if (idx < 0) {
+ node_attach(node, item);
+ } else {
+ node_insert(node, idx, item);
+ }
}
}
return;