diff options
| author | 2012-04-24 01:18:46 +0200 | |
|---|---|---|
| committer | 2012-04-24 01:18:46 +0200 | |
| commit | 728bb0de241ed6fa8694ad68c71287acc8af4241 (patch) | |
| tree | e7d5917ec6b85b45180d8d3c057ed84f79baeb29 /src | |
| parent | 6697e4927883843e1bd537d778fc58bebd9a0b4e (diff) | |
| download | libplist-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.c | 26 |
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) | |||
| 67 | } | 67 | } |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | static void plist_free_node(node_t* node) | 70 | static int plist_free_node(node_t* node) |
| 71 | { | 71 | { |
| 72 | plist_data_t data = NULL; | 72 | plist_data_t data = NULL; |
| 73 | node_detach(node->parent, node); | 73 | int index = node_detach(node->parent, node); |
| 74 | data = plist_get_data(node); | 74 | data = plist_get_data(node); |
| 75 | plist_free_data(data); | 75 | plist_free_data(data); |
| 76 | node->data = NULL; | 76 | node->data = NULL; |
| @@ -83,6 +83,8 @@ static void plist_free_node(node_t* node) | |||
| 83 | node_iterator_destroy(ni); | 83 | node_iterator_destroy(ni); |
| 84 | 84 | ||
| 85 | node_destroy(node); | 85 | node_destroy(node); |
| 86 | |||
| 87 | return index; | ||
| 86 | } | 88 | } |
| 87 | 89 | ||
| 88 | plist_t plist_new_dict(void) | 90 | plist_t plist_new_dict(void) |
| @@ -264,9 +266,12 @@ void plist_array_set_item(plist_t node, plist_t item, uint32_t n) | |||
| 264 | plist_t old_item = plist_array_get_item(node, n); | 266 | plist_t old_item = plist_array_get_item(node, n); |
| 265 | if (old_item) | 267 | if (old_item) |
| 266 | { | 268 | { |
| 267 | plist_free_node(old_item); | 269 | int idx = plist_free_node(old_item); |
| 268 | old_item = NULL; | 270 | if (idx < 0) { |
| 269 | plist_copy_node(item, &old_item); | 271 | node_attach(node, item); |
| 272 | } else { | ||
| 273 | node_insert(node, idx, item); | ||
| 274 | } | ||
| 270 | } | 275 | } |
| 271 | } | 276 | } |
| 272 | return; | 277 | return; |
| @@ -393,12 +398,15 @@ void plist_dict_set_item(plist_t node, const char* key, plist_t item) | |||
| 393 | { | 398 | { |
| 394 | if (node && PLIST_DICT == plist_get_node_type(node)) | 399 | if (node && PLIST_DICT == plist_get_node_type(node)) |
| 395 | { | 400 | { |
| 396 | plist_t old_item = plist_dict_get_item(node, key); | 401 | node_t* old_item = plist_dict_get_item(node, key); |
| 397 | if (old_item) | 402 | if (old_item) |
| 398 | { | 403 | { |
| 399 | plist_free_node(old_item); | 404 | int idx = plist_free_node(old_item); |
| 400 | old_item = NULL; | 405 | if (idx < 0) { |
| 401 | plist_copy_node(item, &old_item); | 406 | node_attach(node, item); |
| 407 | } else { | ||
| 408 | node_insert(node, idx, item); | ||
| 409 | } | ||
| 402 | } | 410 | } |
| 403 | } | 411 | } |
| 404 | return; | 412 | return; |
