diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f046e340..f71b3e921 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ Fixes: * Check for NULL in cJSON_DetachItemViaPointer, fixes #882, see #886 * Fix #881, check overlap before calling strcpy in cJSON_SetValuestring, see #885 * Fix #880 Max recursion depth for cJSON_Duplicate to prevent stack exhaustion, see #888 -* Allocate memory for the temporary buffer when paring numbers, see #939 +* Allocate memory for the temporary buffer when parsing numbers, see #939 * fix the incorrect check in decode_array_index_from_pointer, see #957 1.7.18 (May 13, 2024) diff --git a/cJSON.c b/cJSON.c index 88c2d95b3..90eb84e58 100644 --- a/cJSON.c +++ b/cJSON.c @@ -71,17 +71,17 @@ /* define isnan and isinf for ANSI C, if in C99 or above, isnan and isinf has been defined in math.h */ #ifndef isinf -#define isinf(d) (isnan((d - d)) && !isnan(d)) +#define isinf(d) (isnan(((d) - (d))) && !isnan(d)) #endif #ifndef isnan -#define isnan(d) (d != d) +#define isnan(d) ((d) != (d)) #endif #ifndef NAN #ifdef _WIN32 -#define NAN sqrt(-1.0) +#define NAN (sqrt(-1.0)) #else -#define NAN 0.0/0.0 +#define NAN (0.0/0.0) #endif #endif @@ -585,7 +585,7 @@ static void update_offset(printbuffer * const buffer) buffer->offset += strlen((const char*)buffer_pointer); } -/* securely comparison of floating-point variables */ +/* securely compare floating-point variables */ static cJSON_bool compare_double(double a, double b) { double maxVal = fabs(a) > fabs(b) ? fabs(a) : fabs(b); @@ -785,7 +785,7 @@ static unsigned char utf16_literal_to_utf8(const unsigned char * const input_poi } else if (codepoint <= 0x10FFFF) { - /* four bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx 10xxxxxx */ + /* four bytes, encoding 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */ utf8_length = 4; first_byte_mark = 0xF0; /* 11110000 */ } @@ -820,7 +820,7 @@ static unsigned char utf16_literal_to_utf8(const unsigned char * const input_poi return 0; } -/* Parse the input text into an unescaped cinput, and populate item. */ +/* Parse the input text into an unescaped cstring, and populate item. */ static cJSON_bool parse_string(cJSON * const item, parse_buffer * const input_buffer) { const unsigned char *input_pointer = buffer_at_offset(input_buffer) + 1; @@ -1501,7 +1501,7 @@ static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buf if (input_buffer->depth >= CJSON_NESTING_LIMIT) { - return false; /* to deeply nested */ + return false; /* too deeply nested */ } input_buffer->depth++; @@ -1666,7 +1666,7 @@ static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_bu if (input_buffer->depth >= CJSON_NESTING_LIMIT) { - return false; /* to deeply nested */ + return false; /* too deeply nested */ } input_buffer->depth++; @@ -1691,7 +1691,7 @@ static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_bu /* step back to character in front of the first element */ input_buffer->offset--; - /* loop through the comma separated array elements */ + /* loop through the comma separated object members */ do { /* allocate next item */ @@ -2779,14 +2779,14 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int co } /* Duplication */ -cJSON * cJSON_Duplicate_rec(const cJSON *item, size_t depth, cJSON_bool recurse); +static cJSON *cJSON_Duplicate_rec(const cJSON *item, size_t depth, cJSON_bool recurse); CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) { return cJSON_Duplicate_rec(item, 0, recurse ); } -cJSON * cJSON_Duplicate_rec(const cJSON *item, size_t depth, cJSON_bool recurse) +static cJSON *cJSON_Duplicate_rec(const cJSON *item, size_t depth, cJSON_bool recurse) { cJSON *newitem = NULL; cJSON *child = NULL; diff --git a/cJSON.h b/cJSON.h index cab5feb42..b16c9136c 100644 --- a/cJSON.h +++ b/cJSON.h @@ -111,7 +111,7 @@ typedef struct cJSON /* The type of the item, as above. */ int type; - /* The item's string, if type==cJSON_String and type == cJSON_Raw */ + /* The item's string, if type==cJSON_String or type==cJSON_Raw */ char *valuestring; /* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */ int valueint; @@ -131,13 +131,13 @@ typedef struct cJSON_Hooks typedef int cJSON_bool; -/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them. +/* Limits how deeply nested arrays/objects can be before cJSON refuses to parse or print them. * This is to prevent stack overflows. */ #ifndef CJSON_NESTING_LIMIT #define CJSON_NESTING_LIMIT 1000 #endif -/* Limits the length of circular references can be before cJSON rejects to parse them. +/* Limits how deeply cJSON_Duplicate recurses before it gives up, e.g. because of circular references. * This is to prevent stack overflows. */ #ifndef CJSON_CIRCULAR_LIMIT #define CJSON_CIRCULAR_LIMIT 10000 @@ -212,7 +212,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void); /* Create a string where valuestring references a string so * it will not be freed by cJSON_Delete */ CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string); -/* Create an object/array that only references it's elements so +/* Create an object/array that only references its elements so * they will not be freed by cJSON_Delete */ CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child); CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child); @@ -260,8 +260,8 @@ CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse); * case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */ CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive); -/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings. - * The input pointer json cannot point to a read-only address area, such as a string constant, +/* Minify a string, remove blank characters (such as ' ', '\t', '\r', '\n') and comments from it. + * The input pointer json cannot point to a read-only address area, such as a string constant, * but should point to a readable and writable address area. */ CJSON_PUBLIC(void) cJSON_Minify(char *json); @@ -281,19 +281,19 @@ CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * c #define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number)) /* helper for the cJSON_SetNumberValue macro */ CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number); -#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number)) +#define cJSON_SetNumberValue(object, number) (((object) != NULL) ? cJSON_SetNumberHelper(object, (double)(number)) : (number)) /* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */ CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring); /* If the object is not a boolean type this does nothing and returns cJSON_Invalid else it returns the new type*/ #define cJSON_SetBoolValue(object, boolValue) ( \ - (object != NULL && ((object)->type & (cJSON_False|cJSON_True))) ? \ + ((object) != NULL && ((object)->type & (cJSON_False|cJSON_True))) ? \ (object)->type=((object)->type &(~(cJSON_False|cJSON_True)))|((boolValue)?cJSON_True:cJSON_False) : \ cJSON_Invalid\ ) /* Macro for iterating over an array or object */ -#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next) +#define cJSON_ArrayForEach(element, array) for(element = ((array) != NULL) ? (array)->child : NULL; (element) != NULL; element = (element)->next) /* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */ CJSON_PUBLIC(void *) cJSON_malloc(size_t size); diff --git a/cJSON_Utils.c b/cJSON_Utils.c index 4f3a9ed8d..d2ec16d1f 100644 --- a/cJSON_Utils.c +++ b/cJSON_Utils.c @@ -25,7 +25,7 @@ #define _CRT_SECURE_NO_DEPRECATE #endif -#ifdef __GNUCC__ +#ifdef __GNUC__ #pragma GCC visibility push(default) #endif #if defined(_MSC_VER) @@ -41,12 +41,11 @@ #include #include #include -#include #if defined(_MSC_VER) #pragma warning (pop) #endif -#ifdef __GNUCC__ +#ifdef __GNUC__ #pragma GCC visibility pop #endif @@ -108,7 +107,7 @@ static int compare_strings(const unsigned char *string1, const unsigned char *st return tolower(*string1) - tolower(*string2); } -/* securely comparison of floating-point variables */ +/* securely compare floating-point variables */ static cJSON_bool compare_double(double a, double b) { double maxVal = fabs(a) > fabs(b) ? fabs(a) : fabs(b); @@ -147,7 +146,7 @@ static cJSON_bool compare_pointers(const unsigned char *name, const unsigned cha if (((*pointer != 0) && (*pointer != '/')) != (*name != 0)) { /* one string has ended, the other not */ - return false;; + return false; } return true; @@ -780,7 +779,7 @@ static enum patch_operation decode_patch_operation(const cJSON * const patch, co return INVALID; } -/* overwrite and existing item with another one and free resources on the way */ +/* overwrite an existing item with another one and free resources on the way */ static void overwrite_item(cJSON * const root, const cJSON replacement) { if (root == NULL) diff --git a/cJSON_Utils.h b/cJSON_Utils.h index a970c6504..666096e69 100644 --- a/cJSON_Utils.h +++ b/cJSON_Utils.h @@ -65,7 +65,7 @@ CJSON_PUBLIC(int) cJSONUtils_ApplyPatchesCaseSensitive(cJSON * const object, con // Code not added to library since this strategy is a LOT slower. */ -/* Implement RFC7386 (https://tools.ietf.org/html/rfc7396) JSON Merge Patch spec. */ +/* Implement RFC7396 (https://tools.ietf.org/html/rfc7396) JSON Merge Patch spec. */ /* target will be modified by patch. return value is new ptr for target. */ CJSON_PUBLIC(cJSON *) cJSONUtils_MergePatch(cJSON *target, const cJSON * const patch); CJSON_PUBLIC(cJSON *) cJSONUtils_MergePatchCaseSensitive(cJSON *target, const cJSON * const patch); diff --git a/library_config/uninstall.cmake b/library_config/uninstall.cmake index a40066828..b5040dd1b 100644 --- a/library_config/uninstall.cmake +++ b/library_config/uninstall.cmake @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.5) set(MANIFEST "${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt") if(NOT EXISTS ${MANIFEST}) - message(FATAL_ERROR "Cannot find install mainfest: ${MANIFEST}") + message(FATAL_ERROR "Cannot find install manifest: ${MANIFEST}") endif() file(STRINGS ${MANIFEST} files)