From 6c125d6152e83905f5b93a769d066ac4e437a88f Mon Sep 17 00:00:00 2001 From: npt-1707 Date: Fri, 23 May 2025 03:24:55 +0800 Subject: [PATCH] src/utils/cJSON.cpp: add NULL check in cJSON_InsertItemInArray --- src/utils/cJSON.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/utils/cJSON.cpp b/src/utils/cJSON.cpp index cbdec41..d957fd7 100644 --- a/src/utils/cJSON.cpp +++ b/src/utils/cJSON.cpp @@ -2142,7 +2142,7 @@ CJSON_PUBLIC(void) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newit { cJSON *after_inserted = NULL; - if (which < 0) + if (which < 0 || newitem == NULL) { return; } @@ -2154,6 +2154,10 @@ CJSON_PUBLIC(void) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newit return; } + if (after_inserted != array->child && newitem->prev == NULL) { + return; + } + newitem->next = after_inserted; newitem->prev = after_inserted->prev; after_inserted->prev = newitem;