浏览代码

fix: error list head's prev when detach the last item

miaoerduo 5 年之前
父节点
当前提交
a65abf2f4f
共有 1 个文件被更改,包括 6 次插入0 次删除
  1. 6 0
      cJSON.c

+ 6 - 0
cJSON.c

@@ -2210,6 +2210,12 @@ CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const it
         /* first element */
         /* first element */
         parent->child = item->next;
         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 */
     /* make sure the detached item doesn't point anywhere anymore */
     item->prev = NULL;
     item->prev = NULL;
     item->next = NULL;
     item->next = NULL;