]> git.feebdaed.xyz Git - 0xmirror/cJSON.git/commitdiff
fix: errors in replacing the first item when array_size is 1, and replacing the last...
authormiaoerduo <zhaoyu3210@foxmail.com>
Fri, 3 Apr 2020 06:47:49 +0000 (14:47 +0800)
committerzhaoyu <zhaoyu@sensetime.com>
Fri, 3 Apr 2020 09:21:02 +0000 (17:21 +0800)
cJSON.c

diff --git a/cJSON.c b/cJSON.c
index cc1c0166773a0adc316c77f6754be897c414d24b..23270c482b4a17820c0f78fbc652ad4401258062 100644 (file)
--- 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;