mirror of
https://github.com/DaveGamble/cJSON.git
synced 2024-12-26 04:31:04 +08:00
Merge pull request #456 from miaoerduo/master
fix: some bugs in detach and replace, resolved #467
This commit is contained in:
commit
a82449fa3e
22
cJSON.c
22
cJSON.c
@ -1509,6 +1509,10 @@ static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buf
|
||||
success:
|
||||
input_buffer->depth--;
|
||||
|
||||
if (head != NULL) {
|
||||
head->prev = current_item;
|
||||
}
|
||||
|
||||
item->type = cJSON_Array;
|
||||
item->child = head;
|
||||
|
||||
@ -1681,6 +1685,10 @@ static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_bu
|
||||
success:
|
||||
input_buffer->depth--;
|
||||
|
||||
if (head != NULL) {
|
||||
head->prev = current_item;
|
||||
}
|
||||
|
||||
item->type = cJSON_Object;
|
||||
item->child = head;
|
||||
|
||||
@ -2202,6 +2210,12 @@ CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const it
|
||||
/* first element */
|
||||
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 */
|
||||
item->prev = NULL;
|
||||
item->next = NULL;
|
||||
@ -2299,6 +2313,10 @@ CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON
|
||||
}
|
||||
if (parent->child == item)
|
||||
{
|
||||
if (parent->child->prev == parent->child)
|
||||
{
|
||||
replacement->prev = replacement;
|
||||
}
|
||||
parent->child = replacement;
|
||||
}
|
||||
else
|
||||
@ -2310,6 +2328,10 @@ CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON
|
||||
{
|
||||
replacement->prev->next = replacement;
|
||||
}
|
||||
if (replacement->next == NULL)
|
||||
{
|
||||
parent->child->prev = replacement;
|
||||
}
|
||||
}
|
||||
|
||||
item->next = NULL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user