From b16a23c2bc08846a2dcc68ecb4469816dc8792da Mon Sep 17 00:00:00 2001 From: KarelChanivecky <46802352+KarelChanivecky@users.noreply.github.com> Date: Tue, 25 Feb 2025 14:24:41 -0800 Subject: [PATCH] Fix WINPR_JSON_AddItemToArray compatibility with cJSON < 1.7.13 Modified the WINPR_JSON_AddItemToArray function to not expect a return value from cJSON_AddItemToArray. WINPR_JSON_AddItemToArray failure is given by the same conditions that cause add_item_to_array. add_item_to_array is a private cJSON function called by cJSON_AddItemToArray. The logic analysis is based on cJSON 1.7.12, which is the last release before cJSON_AddItemToArray's signature changed to include a bool return. See https://github.com/DaveGamble/cJSON/blob/v1.7.12/cJSON.c line: 1848. --- winpr/libwinpr/utils/json/json.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/winpr/libwinpr/utils/json/json.c b/winpr/libwinpr/utils/json/json.c index 3fc99dfa0..160e25425 100644 --- a/winpr/libwinpr/utils/json/json.c +++ b/winpr/libwinpr/utils/json/json.c @@ -32,13 +32,11 @@ #if defined(WITH_CJSON) #if CJSON_VERSION_MAJOR == 1 -#if CJSON_VERSION_MINOR <= 7 -#if CJSON_VERSION_PATCH < 13 +#if (CJSON_VERSION_MINOR < 7) || ((CJSON_VERSION_MINOR == 7) && (CJSON_VERSION_PATCH < 13)) #define USE_CJSON_COMPAT #endif #endif #endif -#endif #if defined(WITH_JSONC) #if JSON_C_MAJOR_VERSION == 0 @@ -617,7 +615,14 @@ BOOL WINPR_JSON_AddItemToArray(WINPR_JSON* array, WINPR_JSON* item) return FALSE; return TRUE; #elif defined(WITH_CJSON) +#if defined(USE_CJSON_COMPAT) + if ((array == NULL) || (item == NULL)) + return FALSE; + cJSON_AddItemToArray((cJSON*)array, (cJSON*)item); + return TRUE; +#else return cJSON_AddItemToArray((cJSON*)array, (cJSON*)item); +#endif #else WINPR_UNUSED(array); WINPR_UNUSED(item);