Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 12 additions & 12 deletions cJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 */
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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++;

Expand Down Expand Up @@ -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++;

Expand All @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions cJSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand Down
11 changes: 5 additions & 6 deletions cJSON_Utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#define _CRT_SECURE_NO_DEPRECATE
#endif

#ifdef __GNUCC__
#ifdef __GNUC__
#pragma GCC visibility push(default)
#endif
#if defined(_MSC_VER)
Expand All @@ -41,12 +41,11 @@
#include <limits.h>
#include <math.h>
#include <float.h>
#include <math.h>

#if defined(_MSC_VER)
#pragma warning (pop)
#endif
#ifdef __GNUCC__
#ifdef __GNUC__
#pragma GCC visibility pop
#endif

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cJSON_Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion library_config/uninstall.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down