Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c69134d017 | ||
|
|
563d861f92 | ||
|
|
6820448db5 | ||
|
|
d44b594ab3 | ||
|
|
f110bd2e58 | ||
|
|
5cd1dabb30 | ||
|
|
d606cbbc64 | ||
|
|
be749d7efa | ||
|
|
eaec82c3c5 | ||
|
|
cb1df2f88c | ||
|
|
2c914c073d | ||
|
|
4917024741 | ||
|
|
a3fadd44d1 | ||
|
|
feb05fb2fd | ||
|
|
26f38f4782 | ||
|
|
8e742e4869 | ||
|
|
543ab5d08a | ||
|
|
e2162adeed |
23
.editorconfig
Normal file
23
.editorconfig
Normal file
@@ -0,0 +1,23 @@
|
||||
root = true
|
||||
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[Makefile]
|
||||
indent_style = tab
|
||||
indent_size = unset
|
||||
|
||||
# ignore external repositories and test inputs
|
||||
[tests/{unity,json-patch-tests,inputs}/*]
|
||||
indent_style = unset
|
||||
indent_size = unset
|
||||
end_of_line = unset
|
||||
charset = unset
|
||||
trim_trailing_whitespace = unset
|
||||
insert_final_newline = unset
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -14,3 +14,5 @@ libcjson.so.*
|
||||
libcjson_utils.so.*
|
||||
*.orig
|
||||
.vscode
|
||||
.idea
|
||||
cmake-build-debug
|
||||
|
||||
15
CHANGELOG.md
15
CHANGELOG.md
@@ -1,3 +1,18 @@
|
||||
1.7.10
|
||||
======
|
||||
Fixes:
|
||||
------
|
||||
* Fix package config file for `libcjson`. Thanks @shiluotang for reporting (#321)
|
||||
* Correctly split lists in `cJSON_Utils`'s merge sort. Thanks @andysCaplin for the fix (#322)
|
||||
|
||||
1.7.9
|
||||
=====
|
||||
Fixes:
|
||||
------
|
||||
* Fix a bug where `cJSON_GetObjectItemCaseSensitive` would pass a nullpointer to `strcmp` when called on an array (#315). Thanks @yuweol for reporting.
|
||||
* Fix error in `cJSON_Utils` where the case sensitivity was not respected (#317). Thanks @yuta-oxo for fixing.
|
||||
* Fix some warnings detected by the Visual Studio Static Analyzer (#307). Thanks @bnason-nf
|
||||
|
||||
1.7.8
|
||||
=====
|
||||
Fixes:
|
||||
|
||||
@@ -7,7 +7,7 @@ include(GNUInstallDirs)
|
||||
|
||||
set(PROJECT_VERSION_MAJOR 1)
|
||||
set(PROJECT_VERSION_MINOR 7)
|
||||
set(PROJECT_VERSION_PATCH 8)
|
||||
set(PROJECT_VERSION_PATCH 10)
|
||||
set(CJSON_VERSION_SO 1)
|
||||
set(CJSON_UTILS_VERSION_SO 1)
|
||||
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
|
||||
|
||||
@@ -7,6 +7,7 @@ Current Maintainer: [Max Bruckner](https://github.com/FSMaxB)
|
||||
* [Ajay Bhargav](https://github.com/ajaybhargav)
|
||||
* [Alper Akcan](https://github.com/alperakcan)
|
||||
* [Anton Sergeev](https://github.com/anton-sergeev)
|
||||
* [Benbuck Nason](https://github.com/bnason-nf)
|
||||
* [Bob Kocisko](https://github.com/bobkocisko)
|
||||
* [Christian Schulze](https://github.com/ChristianSch)
|
||||
* [Casperinous](https://github.com/Casperinous)
|
||||
@@ -41,6 +42,7 @@ Current Maintainer: [Max Bruckner](https://github.com/FSMaxB)
|
||||
* [Stephan Gatzka](https://github.com/gatzka)
|
||||
* [Weston Schmidt](https://github.com/schmidtw)
|
||||
* [yangfl](https://github.com/yangfl)
|
||||
* [yuta-oxo](https://github.com/yuta-oxo)
|
||||
* [Zach Hindes](https://github.com/zhindes)
|
||||
* [Zhao Zhixu](https://github.com/zhaozhixu)
|
||||
|
||||
|
||||
4
Makefile
4
Makefile
@@ -8,7 +8,7 @@ CJSON_TEST_SRC = cJSON.c test.c
|
||||
|
||||
LDLIBS = -lm
|
||||
|
||||
LIBVERSION = 1.7.8
|
||||
LIBVERSION = 1.7.10
|
||||
CJSON_SOVERSION = 1
|
||||
UTILS_SOVERSION = 1
|
||||
|
||||
@@ -46,7 +46,7 @@ STATIC = a
|
||||
ifeq (Darwin, $(uname))
|
||||
SHARED = dylib
|
||||
CJSON_SO_LDFLAG = ""
|
||||
UTILS_SO_LDFLAG = ""
|
||||
UTILS_SO_LDFLAG = ""
|
||||
endif
|
||||
|
||||
#cJSON library names
|
||||
|
||||
@@ -298,6 +298,7 @@ In this example we want to build and parse the following JSON:
|
||||
Let's build the above JSON and print it to a string:
|
||||
```c
|
||||
//create a monitor with a list of supported resolutions
|
||||
//NOTE: Returns a heap allocated string, you are required to free it after use.
|
||||
char* create_monitor(void)
|
||||
{
|
||||
const unsigned int resolution_numbers[3][2] = {
|
||||
@@ -373,6 +374,7 @@ end:
|
||||
|
||||
Alternatively we can use the `cJSON_Add...ToObject` helper functions to make our lifes a little easier:
|
||||
```c
|
||||
//NOTE: Returns a heap allocated string, you are required to free it after use.
|
||||
char *create_monitor_with_helpers(void)
|
||||
{
|
||||
const unsigned int resolution_numbers[3][2] = {
|
||||
|
||||
16
cJSON.c
16
cJSON.c
@@ -81,7 +81,7 @@ CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *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 != 8)
|
||||
#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 10)
|
||||
#error cJSON.h and cJSON.c have different versions. Make sure that both have the same.
|
||||
#endif
|
||||
|
||||
@@ -324,7 +324,7 @@ loop_end:
|
||||
{
|
||||
item->valueint = INT_MAX;
|
||||
}
|
||||
else if (number <= INT_MIN)
|
||||
else if (number <= (double)INT_MIN)
|
||||
{
|
||||
item->valueint = INT_MIN;
|
||||
}
|
||||
@@ -346,7 +346,7 @@ CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number)
|
||||
{
|
||||
object->valueint = INT_MAX;
|
||||
}
|
||||
else if (number <= INT_MIN)
|
||||
else if (number <= (double)INT_MIN)
|
||||
{
|
||||
object->valueint = INT_MIN;
|
||||
}
|
||||
@@ -1675,7 +1675,7 @@ static cJSON_bool print_object(const cJSON * const item, printbuffer * const out
|
||||
update_offset(output_buffer);
|
||||
|
||||
/* print comma if not last */
|
||||
length = (size_t) ((output_buffer->format ? 1 : 0) + (current_item->next ? 1 : 0));
|
||||
length = ((size_t)(output_buffer->format ? 1 : 0) + (size_t)(current_item->next ? 1 : 0));
|
||||
output_pointer = ensure(output_buffer, length + 1);
|
||||
if (output_pointer == NULL)
|
||||
{
|
||||
@@ -1781,7 +1781,7 @@ static cJSON *get_object_item(const cJSON * const object, const char * const nam
|
||||
current_element = object->child;
|
||||
if (case_sensitive)
|
||||
{
|
||||
while ((current_element != NULL) && (strcmp(name, current_element->string) != 0))
|
||||
while ((current_element != NULL) && (current_element->string != NULL) && (strcmp(name, current_element->string) != 0))
|
||||
{
|
||||
current_element = current_element->next;
|
||||
}
|
||||
@@ -1794,6 +1794,10 @@ static cJSON *get_object_item(const cJSON * const object, const char * const nam
|
||||
}
|
||||
}
|
||||
|
||||
if ((current_element == NULL) || (current_element->string == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return current_element;
|
||||
}
|
||||
|
||||
@@ -2300,7 +2304,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num)
|
||||
{
|
||||
item->valueint = INT_MAX;
|
||||
}
|
||||
else if (num <= INT_MIN)
|
||||
else if (num <= (double)INT_MIN)
|
||||
{
|
||||
item->valueint = INT_MIN;
|
||||
}
|
||||
|
||||
2
cJSON.h
2
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 8
|
||||
#define CJSON_VERSION_PATCH 10
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
@@ -499,6 +499,7 @@ static cJSON *sort_list(cJSON *list, const cJSON_bool case_sensitive)
|
||||
{
|
||||
/* Split the lists */
|
||||
second->prev->next = NULL;
|
||||
second->prev = NULL;
|
||||
}
|
||||
|
||||
/* Recursively sort the sub-lists. */
|
||||
@@ -510,7 +511,7 @@ static cJSON *sort_list(cJSON *list, const cJSON_bool case_sensitive)
|
||||
while ((first != NULL) && (second != NULL))
|
||||
{
|
||||
cJSON *smaller = NULL;
|
||||
if (compare_strings((unsigned char*)first->string, (unsigned char*)second->string, false) < 0)
|
||||
if (compare_strings((unsigned char*)first->string, (unsigned char*)second->string, case_sensitive) < 0)
|
||||
{
|
||||
smaller = first;
|
||||
}
|
||||
|
||||
@@ -6,5 +6,5 @@ Version: @PROJECT_VERSION@
|
||||
Description: Ultralightweight JSON parser in ANSI C
|
||||
URL: https://github.com/DaveGamble/cJSON
|
||||
Libs: -L${libdir} -lcjson
|
||||
Libs.Private: -lm
|
||||
Libs.private: -lm
|
||||
Cflags: -I${includedir}
|
||||
|
||||
@@ -214,6 +214,7 @@
|
||||
|
||||
{ "doc": {"foo": null},
|
||||
"patch": [{"op": "test", "path": "/foo", "value": null}],
|
||||
"expected": {"foo": null},
|
||||
"comment": "null value should be valid obj property" },
|
||||
|
||||
{ "doc": {"foo": null},
|
||||
@@ -243,14 +244,17 @@
|
||||
|
||||
{ "doc": {"foo": {"foo": 1, "bar": 2}},
|
||||
"patch": [{"op": "test", "path": "/foo", "value": {"bar": 2, "foo": 1}}],
|
||||
"expected": {"foo": {"foo": 1, "bar": 2}},
|
||||
"comment": "test should pass despite rearrangement" },
|
||||
|
||||
{ "doc": {"foo": [{"foo": 1, "bar": 2}]},
|
||||
"patch": [{"op": "test", "path": "/foo", "value": [{"bar": 2, "foo": 1}]}],
|
||||
"expected": {"foo": [{"foo": 1, "bar": 2}]},
|
||||
"comment": "test should pass despite (nested) rearrangement" },
|
||||
|
||||
{ "doc": {"foo": {"bar": [1, 2, 5, 4]}},
|
||||
"patch": [{"op": "test", "path": "/foo", "value": {"bar": [1, 2, 5, 4]}}],
|
||||
"expected": {"foo": {"bar": [1, 2, 5, 4]}},
|
||||
"comment": "test should pass - no error" },
|
||||
|
||||
{ "doc": {"foo": {"bar": [1, 2, 5, 4]}},
|
||||
@@ -264,7 +268,8 @@
|
||||
|
||||
{ "comment": "Empty-string element",
|
||||
"doc": { "": 1 },
|
||||
"patch": [{"op": "test", "path": "/", "value": 1}] },
|
||||
"patch": [{"op": "test", "path": "/", "value": 1}],
|
||||
"expected": { "": 1 } },
|
||||
|
||||
{ "doc": {
|
||||
"foo": ["bar", "baz"],
|
||||
@@ -288,8 +293,23 @@
|
||||
{"op": "test", "path": "/i\\j", "value": 5},
|
||||
{"op": "test", "path": "/k\"l", "value": 6},
|
||||
{"op": "test", "path": "/ ", "value": 7},
|
||||
{"op": "test", "path": "/m~0n", "value": 8}] },
|
||||
|
||||
{"op": "test", "path": "/m~0n", "value": 8}],
|
||||
"expected": {
|
||||
"": 0,
|
||||
" ": 7,
|
||||
"a/b": 1,
|
||||
"c%d": 2,
|
||||
"e^f": 3,
|
||||
"foo": [
|
||||
"bar",
|
||||
"baz"
|
||||
],
|
||||
"g|h": 4,
|
||||
"i\\j": 5,
|
||||
"k\"l": 6,
|
||||
"m~n": 8
|
||||
}
|
||||
},
|
||||
{ "comment": "Move to same location has no effect",
|
||||
"doc": {"foo": 1},
|
||||
"patch": [{"op": "move", "from": "/foo", "path": "/foo"}],
|
||||
@@ -388,11 +408,21 @@
|
||||
"patch": [ { "op": "copy", "path": "/-" } ],
|
||||
"error": "missing 'from' parameter" },
|
||||
|
||||
{ "comment": "missing from location to copy",
|
||||
"doc": { "foo": 1 },
|
||||
"patch": [ { "op": "copy", "from": "/bar", "path": "/foo" } ],
|
||||
"error": "missing 'from' location" },
|
||||
|
||||
{ "comment": "missing from parameter to move",
|
||||
"doc": { "foo": 1 },
|
||||
"patch": [ { "op": "move", "path": "" } ],
|
||||
"error": "missing 'from' parameter" },
|
||||
|
||||
{ "comment": "missing from location to move",
|
||||
"doc": { "foo": 1 },
|
||||
"patch": [ { "op": "move", "from": "/bar", "path": "/foo" } ],
|
||||
"error": "missing 'from' location" },
|
||||
|
||||
{ "comment": "duplicate ops",
|
||||
"doc": { "foo": "bar" },
|
||||
"patch": [ { "op": "add", "path": "/baz", "value": "qux",
|
||||
|
||||
@@ -127,6 +127,28 @@ static void cjson_get_object_item_case_sensitive_should_get_object_items(void)
|
||||
cJSON_Delete(item);
|
||||
}
|
||||
|
||||
static void cjson_get_object_item_should_not_crash_with_array(void) {
|
||||
cJSON *array = NULL;
|
||||
cJSON *found = NULL;
|
||||
array = cJSON_Parse("[1]");
|
||||
|
||||
found = cJSON_GetObjectItem(array, "name");
|
||||
TEST_ASSERT_NULL(found);
|
||||
|
||||
cJSON_Delete(array);
|
||||
}
|
||||
|
||||
static void cjson_get_object_item_case_sensitive_should_not_crash_with_array(void) {
|
||||
cJSON *array = NULL;
|
||||
cJSON *found = NULL;
|
||||
array = cJSON_Parse("[1]");
|
||||
|
||||
found = cJSON_GetObjectItemCaseSensitive(array, "name");
|
||||
TEST_ASSERT_NULL(found);
|
||||
|
||||
cJSON_Delete(array);
|
||||
}
|
||||
|
||||
static void typecheck_functions_should_check_type(void)
|
||||
{
|
||||
cJSON invalid[1];
|
||||
@@ -535,6 +557,8 @@ int CJSON_CDECL main(void)
|
||||
RUN_TEST(cjson_array_foreach_should_not_dereference_null_pointer);
|
||||
RUN_TEST(cjson_get_object_item_should_get_object_items);
|
||||
RUN_TEST(cjson_get_object_item_case_sensitive_should_get_object_items);
|
||||
RUN_TEST(cjson_get_object_item_should_not_crash_with_array);
|
||||
RUN_TEST(cjson_get_object_item_case_sensitive_should_not_crash_with_array);
|
||||
RUN_TEST(typecheck_functions_should_check_type);
|
||||
RUN_TEST(cjson_should_not_parse_to_deeply_nested_jsons);
|
||||
RUN_TEST(cjson_set_number_value_should_set_numbers);
|
||||
|
||||
Reference in New Issue
Block a user