mirror of
https://github.com/DaveGamble/cJSON.git
synced 2024-12-26 21:04:24 +08:00
fix: errors in replacing the first item when array_size is 1, and replacing the last item
This commit is contained in:
parent
a65abf2f4f
commit
cb4661cd91
8
cJSON.c
8
cJSON.c
@ -2313,6 +2313,10 @@ CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON
|
|||||||
}
|
}
|
||||||
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
|
||||||
@ -2324,6 +2328,10 @@ CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON
|
|||||||
{
|
{
|
||||||
replacement->prev->next = replacement;
|
replacement->prev->next = replacement;
|
||||||
}
|
}
|
||||||
|
if (replacement->next == NULL)
|
||||||
|
{
|
||||||
|
parent->child->prev = replacement;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
item->next = NULL;
|
item->next = NULL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user