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.
This commit is contained in:
KarelChanivecky
2025-02-25 14:24:41 -08:00
committed by Armin Novak
parent 458837282e
commit b16a23c2bc

View File

@@ -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);