mirror of
https://github.com/DaveGamble/cJSON.git
synced 2025-09-15 12:58:50 +08:00
Compare commits
6 Commits
65734968c9
...
c7a46d201e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c7a46d201e | ||
|
|
c859b25da0 | ||
|
|
74e1ff4994 | ||
|
|
e6178a0e23 | ||
|
|
3ff8920fba | ||
|
|
7d89f84712 |
12
CHANGELOG.md
12
CHANGELOG.md
@ -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:
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
2
Makefile
2
Makefile
@ -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
44
cJSON.c
@ -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);
|
||||
|
||||
5
cJSON.h
5
cJSON.h
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user