From b5d6cfc759bc77f144c5e296d488c33c44ec7ee5 Mon Sep 17 00:00:00 2001 From: "Markus W. Weissmann" Date: Thu, 2 Jul 2020 11:15:31 +0200 Subject: [PATCH] fix detaching the tail of an array --- cJSON.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cJSON.c b/cJSON.c index a198d66..b3af058 100644 --- a/cJSON.c +++ b/cJSON.c @@ -2117,6 +2117,11 @@ CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const it /* not the last element */ item->next->prev = item->prev; } + else + { + /* the last element - need to fix the prev pointer of the 1st element */ + parent->child->prev = item->prev; + } if (item == parent->child) {