From a65abf2f4f1842765761a616e93c14ae25a284fd Mon Sep 17 00:00:00 2001 From: miaoerduo Date: Fri, 3 Apr 2020 14:07:22 +0800 Subject: [PATCH] fix: error list head's prev when detach the last item --- cJSON.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cJSON.c b/cJSON.c index 500fcf5..cc1c016 100644 --- a/cJSON.c +++ b/cJSON.c @@ -2210,6 +2210,12 @@ CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const it /* first element */ 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 */ item->prev = NULL; item->next = NULL;