From cb4661cd91fc6d6f9e81b627967735f7072f901c Mon Sep 17 00:00:00 2001 From: miaoerduo Date: Fri, 3 Apr 2020 14:47:49 +0800 Subject: [PATCH] fix: errors in replacing the first item when array_size is 1, and replacing the last item --- cJSON.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cJSON.c b/cJSON.c index cc1c016..23270c4 100644 --- a/cJSON.c +++ b/cJSON.c @@ -2313,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 @@ -2324,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;