Skip to content
Snippets Groups Projects
Commit 720aa16524ae authored by Alan Wang's avatar Alan Wang
Browse files

Merge pull request #456 from miaoerduo/master

fix: some bugs in detach and replace, resolved #467
Branches
No related tags found
No related merge requests found
...@@ -1509,6 +1509,10 @@ ...@@ -1509,6 +1509,10 @@
success: success:
input_buffer->depth--; input_buffer->depth--;
if (head != NULL) {
head->prev = current_item;
}
item->type = cJSON_Array; item->type = cJSON_Array;
item->child = head; item->child = head;
...@@ -1681,6 +1685,10 @@ ...@@ -1681,6 +1685,10 @@
success: success:
input_buffer->depth--; input_buffer->depth--;
if (head != NULL) {
head->prev = current_item;
}
item->type = cJSON_Object; item->type = cJSON_Object;
item->child = head; item->child = head;
...@@ -2202,6 +2210,12 @@ ...@@ -2202,6 +2210,12 @@
/* first element */ /* first element */
parent->child = item->next; parent->child = item->next;
} }
else if (item->next == NULL)
{
/* last element */
parent->child->prev = item->prev;
}
/* make sure the detached item doesn't point anywhere anymore */ /* make sure the detached item doesn't point anywhere anymore */
item->prev = NULL; item->prev = NULL;
item->next = NULL; item->next = NULL;
...@@ -2299,6 +2313,10 @@ ...@@ -2299,6 +2313,10 @@
} }
if (parent->child == item) if (parent->child == item)
{ {
if (parent->child->prev == parent->child)
{
replacement->prev = replacement;
}
parent->child = replacement; parent->child = replacement;
} }
else else
...@@ -2310,6 +2328,10 @@ ...@@ -2310,6 +2328,10 @@
{ {
replacement->prev->next = replacement; replacement->prev->next = replacement;
} }
if (replacement->next == NULL)
{
parent->child->prev = replacement;
}
} }
item->next = NULL; item->next = NULL;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment