# HG changeset patch
# User miaoerduo <zhaoyu3210@foxmail.com>
# Date 1585896469 -28800
#      Fri Apr 03 14:47:49 2020 +0800
# Node ID 5a3fa70ed7bc217d20a7045f99182753011da90e
# Parent  4588f15d4fb4165b1b84753c5fbaaac82ae868be
fix: errors in replacing the first item when array_size is 1, and replacing the last item

diff --git a/cJSON.c b/cJSON.c
--- a/cJSON.c
+++ b/cJSON.c
@@ -2313,6 +2313,10 @@
     }
     if (parent->child == item)
     {
+        if (parent->child->prev == parent->child)
+        {
+            replacement->prev = replacement;
+        }
         parent->child = replacement;
     }
     else
@@ -2324,6 +2328,10 @@
         {
             replacement->prev->next = replacement;
         }
+        if (replacement->next == NULL)
+        {
+            parent->child->prev = replacement;
+        }
     }
 
     item->next = NULL;