Compare commits

...

6 Commits

Author SHA1 Message Date
Ajay Bhargav
c7a46d201e
Merge e6178a0e23 into c859b25da0 2025-09-12 09:54:57 +07:00
Alan Wang
c859b25da0
Release 1.7.19 (#958)
Some checks failed
CI / linux (CLANG, ENABLE_SANITIZERS) (push) Has been cancelled
CI / linux (CLANG, ENABLE_VALGRIND) (push) Has been cancelled
CI / linux (CLANG, NONE_MEM_CHECK) (push) Has been cancelled
CI / linux (GCC, ENABLE_SANITIZERS) (push) Has been cancelled
CI / linux (GCC, ENABLE_VALGRIND) (push) Has been cancelled
CI / linux (GCC, NONE_MEM_CHECK) (push) Has been cancelled
CI / macos (CLANG, ENABLE_SANITIZERS) (push) Has been cancelled
CI / macos (CLANG, ENABLE_VALGRIND) (push) Has been cancelled
CI / macos (CLANG, NONE_MEM_CHECK) (push) Has been cancelled
CI / macos (GCC, ENABLE_SANITIZERS) (push) Has been cancelled
CI / macos (GCC, ENABLE_VALGRIND) (push) Has been cancelled
CI / macos (GCC, NONE_MEM_CHECK) (push) Has been cancelled
2025-09-09 21:56:10 +08:00
Lee
74e1ff4994
fix the incorrect check in decode_array_index_from_pointer (#957)
Some checks failed
CI / linux (CLANG, ENABLE_SANITIZERS) (push) Has been cancelled
CI / linux (CLANG, ENABLE_VALGRIND) (push) Has been cancelled
CI / linux (CLANG, NONE_MEM_CHECK) (push) Has been cancelled
CI / linux (GCC, ENABLE_SANITIZERS) (push) Has been cancelled
CI / linux (GCC, ENABLE_VALGRIND) (push) Has been cancelled
CI / linux (GCC, NONE_MEM_CHECK) (push) Has been cancelled
CI / macos (CLANG, ENABLE_SANITIZERS) (push) Has been cancelled
CI / macos (CLANG, ENABLE_VALGRIND) (push) Has been cancelled
CI / macos (CLANG, NONE_MEM_CHECK) (push) Has been cancelled
CI / macos (GCC, ENABLE_SANITIZERS) (push) Has been cancelled
CI / macos (GCC, ENABLE_VALGRIND) (push) Has been cancelled
CI / macos (GCC, NONE_MEM_CHECK) (push) Has been cancelled
this fixes CVE-2025-57052
2025-09-05 14:53:20 +08:00
Ajay Bhargav
e6178a0e23 tests:Update misc_tests for cJSON structure change
Signed-off-by: Ajay Bhargav <contact@rickeyworld.info>
2022-10-04 23:05:43 +05:30
Ajay Bhargav
3ff8920fba Update cJSON_Utils for structural changes
Signed-off-by: Ajay Bhargav <contact@rickeyworld.info>
2022-10-04 23:03:50 +05:30
Ajay Bhargav
7d89f84712 Add API for adding number with fix decimal places
Signed-off-by: Ajay Bhargav <contact@rickeyworld.info>
2022-10-04 23:03:50 +05:30
8 changed files with 61 additions and 15 deletions

View File

@ -1,3 +1,15 @@
1.7.19 (Sep 9, 2025)
======
Fixes:
------
* Fix indentation (should use spaces), see #814
* Fix spelling errors found by CodeSpell, see #841
* 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
* fix the incorrect check in decode_array_index_from_pointer, see #957
1.7.18 (May 13, 2024)
======
Fixes:

View File

@ -2,7 +2,7 @@ set(CMAKE_LEGACY_CYGWIN_WIN32 0)
cmake_minimum_required(VERSION 3.0)
project(cJSON
VERSION 1.7.18
VERSION 1.7.19
LANGUAGES C)
cmake_policy(SET CMP0054 NEW) # set CMP0054 policy

View File

@ -24,6 +24,7 @@ Contributors:
* [Debora Grosse](https://github.com/DeboraG)
* [dieyushi](https://github.com/dieyushi)
* [Dōngwén Huáng (黄东文)](https://github.com/DongwenHuang)
* [Dominik](https://github.com/DL6ER)
* [Donough Liu](https://github.com/ldm0)
* [Erez Oxman](https://github.com/erez-o)
* Eswar Yaganti
@ -80,6 +81,8 @@ Contributors:
* [Stephan Gatzka](https://github.com/gatzka)
* [Tony Langhammer](https://github.com/BigBrainAFK)
* [Vemake](https://github.com/vemakereporter)
* [vwvw](https://github.com/vwvw)
* [warmsocks](https://github.com/warmsocks)
* [Wei Tan](https://github.com/tan-wei)
* [Weston Schmidt](https://github.com/schmidtw)
* [xiaomianhehe](https://github.com/xiaomianhehe)

View File

@ -8,7 +8,7 @@ CJSON_TEST_SRC = cJSON.c test.c
LDLIBS = -lm
LIBVERSION = 1.7.18
LIBVERSION = 1.7.19
CJSON_SOVERSION = 1
UTILS_SOVERSION = 1

44
cJSON.c
View File

@ -117,7 +117,7 @@ CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item)
}
/* 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 != 18)
#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 19)
#error cJSON.h and cJSON.c have different versions. Make sure that both have the same.
#endif
@ -614,14 +614,20 @@ static cJSON_bool print_number(const cJSON * const item, printbuffer * const out
}
else
{
/* Try 15 decimal places of precision to avoid nonsignificant nonzero digits */
length = sprintf((char*)number_buffer, "%1.15g", d);
/* If decimal places are present and value is not an integer type */
if (item->decimal_places && (ceil(d) != d)) {
/* Then convert it to string */
length = sprintf((char*) number_buffer, "%.*f", item->decimal_places, d);
} else {
/* Try 15 decimal places of precision to avoid nonsignificant nonzero digits */
length = sprintf((char*)number_buffer, "%1.15g", d);
/* Check whether the original double can be recovered */
if ((sscanf((char*)number_buffer, "%lg", &test) != 1) || !compare_double((double)test, d))
{
/* If not, print with 17 decimal places of precision */
length = sprintf((char*)number_buffer, "%1.17g", d);
/* Check whether the original double can be recovered */
if ((sscanf((char*)number_buffer, "%lg", &test) != 1) || !compare_double((double)test, d))
{
/* If not, print with 17 decimal places of precision */
length = sprintf((char*)number_buffer, "%1.17g", d);
}
}
}
@ -2192,6 +2198,28 @@ CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char *
return NULL;
}
CJSON_PUBLIC(cJSON*) cJSON_AddNumberWithPrecisionToObject(cJSON * const object, const char * const name, const double n, int decimal_places)
{
cJSON *number_item;
if (decimal_places <= 0 || decimal_places > 14)
{
return NULL;
}
number_item = cJSON_CreateNumber(n);
number_item->decimal_places = decimal_places;
if (add_item_to_object(object, name, number_item, &global_hooks, false))
{
return number_item;
}
cJSON_Delete(number_item);
return NULL;
}
CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string)
{
cJSON *string_item = cJSON_CreateString(string);

View File

@ -81,7 +81,7 @@ then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJ
/* project version */
#define CJSON_VERSION_MAJOR 1
#define CJSON_VERSION_MINOR 7
#define CJSON_VERSION_PATCH 18
#define CJSON_VERSION_PATCH 19
#include <stddef.h>
@ -117,6 +117,8 @@ typedef struct cJSON
int valueint;
/* The item's number, if type==cJSON_Number */
double valuedouble;
/* Decimal places */
int decimal_places;
/* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
char *string;
@ -272,6 +274,7 @@ CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * co
CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean);
CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number);
CJSON_PUBLIC(cJSON*) cJSON_AddNumberWithPrecisionToObject(cJSON * const object, const char * const name, const double n, int decimal_places);
CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string);
CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw);
CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name);

View File

@ -282,7 +282,7 @@ static cJSON_bool decode_array_index_from_pointer(const unsigned char * const po
return 0;
}
for (position = 0; (pointer[position] >= '0') && (pointer[0] <= '9'); position++)
for (position = 0; (pointer[position] >= '0') && (pointer[position] <= '9'); position++)
{
parsed_index = (10 * parsed_index) + (size_t)(pointer[position] - '0');
@ -840,7 +840,7 @@ static int apply_patch(cJSON *object, const cJSON *patch, const cJSON_bool case_
{
if (opcode == REMOVE)
{
static const cJSON invalid = { NULL, NULL, NULL, cJSON_Invalid, NULL, 0, 0, NULL};
static const cJSON invalid = { NULL, NULL, NULL, cJSON_Invalid, NULL, 0, 0, 0, NULL};
overwrite_item(object, invalid);

View File

@ -238,7 +238,7 @@ static void cjson_should_not_follow_too_deep_circular_references(void)
static void cjson_set_number_value_should_set_numbers(void)
{
cJSON number[1] = {{NULL, NULL, NULL, cJSON_Number, NULL, 0, 0, NULL}};
cJSON number[1] = {{NULL, NULL, NULL, cJSON_Number, NULL, 0, 0, 0, NULL}};
cJSON_SetNumberValue(number, 1.5);
TEST_ASSERT_EQUAL(1, number->valueint);
@ -360,7 +360,7 @@ static void cjson_replace_item_via_pointer_should_replace_items(void)
static void cjson_replace_item_in_object_should_preserve_name(void)
{
cJSON root[1] = {{NULL, NULL, NULL, 0, NULL, 0, 0, NULL}};
cJSON root[1] = {{NULL, NULL, NULL, 0, NULL, 0, 0, 0, NULL}};
cJSON *child = NULL;
cJSON *replacement = NULL;
cJSON_bool flag = false;