--- embedaddon/iperf/src/cjson.c 2021/03/17 00:36:46 1.1.1.2 +++ embedaddon/iperf/src/cjson.c 2023/09/27 11:14:54 1.1.1.3 @@ -37,6 +37,7 @@ #pragma warning (disable : 4001) #endif +#include "iperf_config.h" #include #include #include @@ -82,9 +83,32 @@ #endif #ifndef NAN +#ifdef _WIN32 +#define NAN sqrt(-1.0) +#else #define NAN 0.0/0.0 #endif +#endif +#if defined(HAVE_INTTYPES_H) +# include +#else +# ifndef PRIu64 +# if sizeof(long) == 8 +# define PRIu64 "lu" +# else +# define PRIu64 "llu" +# endif +# ifndef PRId64 +# if sizeof(long) == 8 +# define PRId64 "ld" +# else +# define PRId64 "lld" +# endif +# endif +# endif +#endif + typedef struct { const unsigned char *json; size_t position; @@ -103,9 +127,9 @@ CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void) return (const char*) (global_error.json + global_error.position); } -CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item) +CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item) { - if (!cJSON_IsString(item)) + if (!cJSON_IsString(item)) { return NULL; } @@ -113,18 +137,18 @@ CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item) return item->valuestring; } -CJSON_PUBLIC(double) cJSON_GetNumberValue(cJSON *item) +CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item) { - if (!cJSON_IsNumber(item)) + if (!cJSON_IsNumber(item)) { - return NAN; + return (double) NAN; // cppcheck-suppress invalidFunctionArg } return item->valuedouble; } /* This is a safeguard to prevent copy-pasters from using incompatible C and header files */ -#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 13) +#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 15) #error cJSON.h and cJSON.c have different versions. Make sure that both have the same. #endif @@ -518,10 +542,8 @@ static unsigned char* ensure(printbuffer * const p, si return NULL; } - if (newbuffer) - { - memcpy(newbuffer, p->buffer, p->offset + 1); - } + + memcpy(newbuffer, p->buffer, p->offset + 1); p->hooks.deallocate(p->buffer); } p->length = newsize; @@ -571,6 +593,10 @@ static cJSON_bool print_number(const cJSON * const ite { length = sprintf((char*)number_buffer, "null"); } + else if(d == (double)item->valueint) + { + length = sprintf((char*)number_buffer, "%" PRId64, item->valueint); + } else { /* Try 15 decimal places of precision to avoid nonsignificant nonzero digits */ @@ -1112,7 +1138,7 @@ CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const } buffer.content = (const unsigned char*)value; - buffer.length = buffer_length; + buffer.length = buffer_length; buffer.offset = 0; buffer.hooks = global_hooks; @@ -1520,6 +1546,10 @@ static cJSON_bool parse_array(cJSON * const item, pars success: input_buffer->depth--; + if (head != NULL) { + head->prev = current_item; + } + item->type = cJSON_Array; item->child = head; @@ -1692,6 +1722,10 @@ static cJSON_bool parse_object(cJSON * const item, par success: input_buffer->depth--; + if (head != NULL) { + head->prev = current_item; + } + item->type = cJSON_Object; item->child = head; @@ -1978,15 +2012,6 @@ static cJSON_bool add_item_to_array(cJSON *array, cJSO suffix_object(child->prev, item); array->child->prev = item; } - else - { - while (child->next) - { - child = child->next; - } - suffix_object(child, item); - array->child->prev = item; - } } return true; @@ -2213,6 +2238,12 @@ CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON /* 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; @@ -2310,6 +2341,10 @@ CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(c } if (parent->child == item) { + if (parent->child->prev == parent->child) + { + replacement->prev = replacement; + } parent->child = replacement; } else @@ -2321,6 +2356,10 @@ CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(c { replacement->prev->next = replacement; } + if (replacement->next == NULL) + { + parent->child->prev = replacement; + } } item->next = NULL; @@ -2353,6 +2392,11 @@ static cJSON_bool replace_item_in_object(cJSON *object cJSON_free(replacement->string); } replacement->string = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks); + if (replacement->string == NULL) + { + return false; + } + replacement->type &= ~cJSON_StringIsConst; return cJSON_ReplaceItemViaPointer(object, get_object_item(object, string, case_sensitive), replacement); @@ -2542,6 +2586,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int * } a = cJSON_CreateArray(); + for(i = 0; a && (i < (size_t)count); i++) { n = cJSON_CreateNumber(numbers[i]); @@ -2561,6 +2606,10 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int * p = n; } + if (a && a->child) { + a->child->prev = n; + } + return a; } @@ -2597,6 +2646,10 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const flo p = n; } + if (a && a->child) { + a->child->prev = n; + } + return a; } @@ -2614,7 +2667,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const do a = cJSON_CreateArray(); - for(i = 0;a && (i < (size_t)count); i++) + for(i = 0; a && (i < (size_t)count); i++) { n = cJSON_CreateNumber(numbers[i]); if(!n) @@ -2633,6 +2686,10 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const do p = n; } + if (a && a->child) { + a->child->prev = n; + } + return a; } @@ -2669,6 +2726,10 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const ch p = n; } + if (a && a->child) { + a->child->prev = n; + } + return a; } @@ -2740,6 +2801,10 @@ CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *ite } child = child->next; } + if (newitem && newitem->child) + { + newitem->child->prev = newchild; + } return newitem; @@ -2951,7 +3016,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * con CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive) { - if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF)) || cJSON_IsInvalid(a)) + if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF))) { return false; }