Compare commits
37 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d348621ca9 | ||
|
|
744e47353a | ||
|
|
7795249dd4 | ||
|
|
324a6ac9a9 | ||
|
|
6ea4c01e4e | ||
|
|
9226e4ed8c | ||
|
|
7b6645794d | ||
|
|
4100379a04 | ||
|
|
2f6fc7f0f2 | ||
|
|
a1e1c208ff | ||
|
|
9bf4960cd5 | ||
|
|
488169faca | ||
|
|
9931900768 | ||
|
|
d2735278ed | ||
|
|
8e84db4c4e | ||
|
|
8e357f825b | ||
|
|
2e5171d8d6 | ||
|
|
c8ca78a3cc | ||
|
|
0b13220419 | ||
|
|
23f027139e | ||
|
|
60c3b0a571 | ||
|
|
857c037ccc | ||
|
|
3fb9d929e1 | ||
|
|
cf97c6f066 | ||
|
|
1ef4deec06 | ||
|
|
4578d3a9e1 | ||
|
|
b95a4c56b0 | ||
|
|
7db005e028 | ||
|
|
1fc755ac09 | ||
|
|
a82449fa3e | ||
|
|
2a6299d904 | ||
|
|
43f471bff1 | ||
|
|
7103844037 | ||
|
|
3442b36672 | ||
|
|
cb4661cd91 | ||
|
|
a65abf2f4f | ||
|
|
3999b12848 |
9
.gitattributes
vendored
9
.gitattributes
vendored
@@ -1,2 +1,11 @@
|
||||
* text=auto
|
||||
/tests/inputs/* text eol=lf
|
||||
|
||||
.gitattributes export-ignore
|
||||
.gitignore export-ignore
|
||||
.github export-ignore
|
||||
.editorconfig export-ignore
|
||||
.travis.yml export-ignore
|
||||
|
||||
# Linguist incorrectly identified the headers as C++, manually override this.
|
||||
*.h linguist-language=C
|
||||
|
||||
102
.github/workflows/CI.yml
vendored
Normal file
102
.github/workflows/CI.yml
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
paths-ignore:
|
||||
- '**.md'
|
||||
- 'LICENSE'
|
||||
pull_request:
|
||||
types: [opened, synchronize]
|
||||
paths-ignore:
|
||||
- '**.md'
|
||||
- 'LICENSE'
|
||||
|
||||
jobs:
|
||||
linux:
|
||||
runs-on: ubuntu-latest
|
||||
if: "!contains(github.event.head_commit.message, 'ci skip')"
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
mem_check:
|
||||
- ENABLE_VALGRIND
|
||||
- ENABLE_SANITIZERS
|
||||
- NONE_MEM_CHECK
|
||||
compiler:
|
||||
- GCC
|
||||
- CLANG
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: install build dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install clang-8 valgrind
|
||||
- name: build and test
|
||||
shell: bash
|
||||
run: |
|
||||
if [ "${{ matrix.mem_check }}" == "ENABLE_VALGRIND" ]; then
|
||||
EVENT_CMAKE_OPTIONS="-DENABLE_CJSON_UTILS=ON -DENABLE_VALGRIND=ON -DENABLE_SAFE_STACK=ON -DENABLE_SANITIZERS=OFF"
|
||||
elif [ "${{ matrix.mem_check }}" == "ENABLE_SANITIZERS" ]; then
|
||||
EVENT_CMAKE_OPTIONS="-DENABLE_CJSON_UTILS=ON -DENABLE_VALGRIND=OFF -DENABLE_SAFE_STACK=OFF -DENABLE_SANITIZERS=ON"
|
||||
else
|
||||
EVENT_CMAKE_OPTIONS="-DENABLE_CJSON_UTILS=ON -DENABLE_VALGRIND=OFF -DENABLE_SAFE_STACK=OFF -DENABLE_SANITIZERS=OFF"
|
||||
fi
|
||||
if [ "${{ matrix.compiler }}" == "GCC" ]; then
|
||||
export CC=gcc
|
||||
else
|
||||
export CC=clang
|
||||
fi
|
||||
#run build and test
|
||||
JOBS=20
|
||||
export CTEST_PARALLEL_LEVEL=$JOBS
|
||||
export CTEST_OUTPUT_ON_FAILURE=1
|
||||
mkdir -p build
|
||||
cd build
|
||||
echo [cmake]: cmake .. $EVENT_CMAKE_OPTIONS
|
||||
cmake .. $EVENT_CMAKE_OPTIONS || (rm -rf * && cmake .. $EVENT_CMAKE_OPTIONS)
|
||||
cmake --build .
|
||||
make
|
||||
make test
|
||||
|
||||
macos:
|
||||
runs-on: macos-latest
|
||||
if: "!contains(github.event.head_commit.message, 'ci skip')"
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
mem_check:
|
||||
- ENABLE_VALGRIND
|
||||
- ENABLE_SANITIZERS
|
||||
- NONE_MEM_CHECK
|
||||
compiler:
|
||||
- GCC
|
||||
- CLANG
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: build and test
|
||||
shell: bash
|
||||
run: |
|
||||
if [ "${{ matrix.mem_check }}" == "ENABLE_VALGRIND" ]; then
|
||||
EVENT_CMAKE_OPTIONS="-DENABLE_CJSON_UTILS=ON -DENABLE_VALGRIND=ON -DENABLE_SAFE_STACK=ON -DENABLE_SANITIZERS=OFF"
|
||||
elif [ "${{ matrix.mem_check }}" == "ENABLE_SANITIZERS" ]; then
|
||||
EVENT_CMAKE_OPTIONS="-DENABLE_CJSON_UTILS=ON -DENABLE_VALGRIND=OFF -DENABLE_SAFE_STACK=OFF -DENABLE_SANITIZERS=ON"
|
||||
else
|
||||
EVENT_CMAKE_OPTIONS="-DENABLE_CJSON_UTILS=ON -DENABLE_VALGRIND=OFF -DENABLE_SAFE_STACK=OFF -DENABLE_SANITIZERS=OFF"
|
||||
fi
|
||||
if [ "${{ matrix.compiler }}" == "GCC" ]; then
|
||||
export CC=gcc
|
||||
else
|
||||
export CC=clang
|
||||
fi
|
||||
#run build and test
|
||||
JOBS=20
|
||||
export CTEST_PARALLEL_LEVEL=$JOBS
|
||||
export CTEST_OUTPUT_ON_FAILURE=1
|
||||
mkdir -p build
|
||||
cd build
|
||||
echo [cmake]: cmake .. $EVENT_CMAKE_OPTIONS
|
||||
cmake .. $EVENT_CMAKE_OPTIONS || (rm -rf * && cmake .. $EVENT_CMAKE_OPTIONS)
|
||||
cmake --build .
|
||||
make
|
||||
make test
|
||||
18
CHANGELOG.md
18
CHANGELOG.md
@@ -1,3 +1,21 @@
|
||||
1.7.15 (Aug 25, 2021)
|
||||
======
|
||||
Fixes:
|
||||
------
|
||||
* Fix potential core dumped for strrchr, see [#546](https://github.com/DaveGamble/cJSON/pull/546)
|
||||
* Fix null pointer crash in cJSON_CreateXxArray, see [#538](https://github.com/DaveGamble/cJSON/pull/538)
|
||||
* Fix several null pointer problems on allocation failure, see [#526](https://github.com/DaveGamble/cJSON/pull/526)
|
||||
* Fix a possible dereference of null pointer, see [#519](https://github.com/DaveGamble/cJSON/pull/519)
|
||||
* Fix windows build failure about defining nan, see [#518](https://github.com/DaveGamble/cJSON/pull/518)
|
||||
|
||||
1.7.14 (Sep 3, 2020)
|
||||
======
|
||||
Fixes:
|
||||
------
|
||||
* optimize the way to find tail node, see [#503](https://github.com/DaveGamble/cJSON/pull/503)
|
||||
* Fix WError error on macosx because NAN is a float. Thanks @sappo, see [#484](https://github.com/DaveGamble/cJSON/pull/484)
|
||||
* Fix some bugs in detach and replace. Thanks @miaoerduo, see [#456](https://github.com/DaveGamble/cJSON/pull/456)
|
||||
|
||||
1.7.13 (Apr 2, 2020)
|
||||
======
|
||||
Features:
|
||||
|
||||
@@ -7,7 +7,7 @@ include(GNUInstallDirs)
|
||||
|
||||
set(PROJECT_VERSION_MAJOR 1)
|
||||
set(PROJECT_VERSION_MINOR 7)
|
||||
set(PROJECT_VERSION_PATCH 13)
|
||||
set(PROJECT_VERSION_PATCH 15)
|
||||
set(CJSON_VERSION_SO 1)
|
||||
set(CJSON_UTILS_VERSION_SO 1)
|
||||
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
|
||||
@@ -68,7 +68,6 @@ if (ENABLE_SANITIZERS)
|
||||
-fno-omit-frame-pointer
|
||||
-fsanitize=address
|
||||
-fsanitize=undefined
|
||||
-fsanitize=float-divide-by-zero
|
||||
-fsanitize=float-cast-overflow
|
||||
-fsanitize-address-use-after-scope
|
||||
-fsanitize=integer
|
||||
@@ -223,10 +222,12 @@ configure_file(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/library_config/cJSONConfigVersion.cmake.in"
|
||||
${PROJECT_BINARY_DIR}/cJSONConfigVersion.cmake @ONLY)
|
||||
|
||||
# Install package config files
|
||||
install(FILES ${PROJECT_BINARY_DIR}/cJSONConfig.cmake
|
||||
${PROJECT_BINARY_DIR}/cJSONConfigVersion.cmake
|
||||
DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/cJSON")
|
||||
if(ENABLE_TARGET_EXPORT)
|
||||
# Install package config files
|
||||
install(FILES ${PROJECT_BINARY_DIR}/cJSONConfig.cmake
|
||||
${PROJECT_BINARY_DIR}/cJSONConfigVersion.cmake
|
||||
DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/cJSON")
|
||||
endif()
|
||||
|
||||
option(ENABLE_CJSON_TEST "Enable building cJSON test" ON)
|
||||
if(ENABLE_CJSON_TEST)
|
||||
|
||||
@@ -29,6 +29,7 @@ Contributors:
|
||||
* [Fabrice Fontaine](https://github.com/ffontaine)
|
||||
* Ian Mobley
|
||||
* Irwan Djadjadi
|
||||
* [HuKeping](https://github.com/HuKeping)
|
||||
* [IvanVoid](https://github.com/npi3pak)
|
||||
* [Jakub Wilk](https://github.com/jwilk)
|
||||
* [Jiri Zouhar](https://github.com/loigu)
|
||||
@@ -36,12 +37,15 @@ Contributors:
|
||||
* [Julian Ste](https://github.com/julian-st)
|
||||
* [Julián Vásquez](https://github.com/juvasquezg)
|
||||
* [Kevin Branigan](https://github.com/kbranigan)
|
||||
* [Kevin Sapper](https://github.com/sappo)
|
||||
* [Kyle Chisholm](https://github.com/ChisholmKyle)
|
||||
* [Linus Wallgren](https://github.com/ecksun)
|
||||
* [Mateusz Szafoni](https://github.com/raiden00pl)
|
||||
* Mike Pontillo
|
||||
* [miaoerduo](https://github.com/miaoerduo)
|
||||
* [Mike Jerris](https://github.com/mjerris)
|
||||
* [Mike Robinson](https://github.com/mhrobinson)
|
||||
* [Moorthy](https://github.com/moorthy-bs)
|
||||
* [myd7349](https://github.com/myd7349)
|
||||
* [NancyLi1013](https://github.com/NancyLi1013)
|
||||
* Paulo Antonio Alvarez
|
||||
|
||||
2
Makefile
2
Makefile
@@ -8,7 +8,7 @@ CJSON_TEST_SRC = cJSON.c test.c
|
||||
|
||||
LDLIBS = -lm
|
||||
|
||||
LIBVERSION = 1.7.13
|
||||
LIBVERSION = 1.7.15
|
||||
CJSON_SOVERSION = 1
|
||||
UTILS_SOVERSION = 1
|
||||
|
||||
|
||||
74
cJSON.c
74
cJSON.c
@@ -78,8 +78,12 @@
|
||||
#endif
|
||||
|
||||
#ifndef NAN
|
||||
#ifdef _WIN32
|
||||
#define NAN sqrt(-1.0)
|
||||
#else
|
||||
#define NAN 0.0/0.0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
const unsigned char *json;
|
||||
@@ -92,7 +96,7 @@ CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void)
|
||||
return (const char*) (global_error.json + global_error.position);
|
||||
}
|
||||
|
||||
CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item)
|
||||
CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item)
|
||||
{
|
||||
if (!cJSON_IsString(item))
|
||||
{
|
||||
@@ -102,18 +106,18 @@ CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item)
|
||||
return item->valuestring;
|
||||
}
|
||||
|
||||
CJSON_PUBLIC(double) cJSON_GetNumberValue(cJSON *item)
|
||||
CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item)
|
||||
{
|
||||
if (!cJSON_IsNumber(item))
|
||||
{
|
||||
return NAN;
|
||||
return (double) NAN;
|
||||
}
|
||||
|
||||
return item->valuedouble;
|
||||
}
|
||||
|
||||
/* 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 != 13)
|
||||
#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 15)
|
||||
#error cJSON.h and cJSON.c have different versions. Make sure that both have the same.
|
||||
#endif
|
||||
|
||||
@@ -507,10 +511,8 @@ static unsigned char* ensure(printbuffer * const p, size_t needed)
|
||||
|
||||
return NULL;
|
||||
}
|
||||
if (newbuffer)
|
||||
{
|
||||
memcpy(newbuffer, p->buffer, p->offset + 1);
|
||||
}
|
||||
|
||||
memcpy(newbuffer, p->buffer, p->offset + 1);
|
||||
p->hooks.deallocate(p->buffer);
|
||||
}
|
||||
p->length = newsize;
|
||||
@@ -1509,6 +1511,10 @@ static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buf
|
||||
success:
|
||||
input_buffer->depth--;
|
||||
|
||||
if (head != NULL) {
|
||||
head->prev = current_item;
|
||||
}
|
||||
|
||||
item->type = cJSON_Array;
|
||||
item->child = head;
|
||||
|
||||
@@ -1681,6 +1687,10 @@ static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_bu
|
||||
success:
|
||||
input_buffer->depth--;
|
||||
|
||||
if (head != NULL) {
|
||||
head->prev = current_item;
|
||||
}
|
||||
|
||||
item->type = cJSON_Object;
|
||||
item->child = head;
|
||||
|
||||
@@ -1967,15 +1977,6 @@ static cJSON_bool add_item_to_array(cJSON *array, cJSON *item)
|
||||
suffix_object(child->prev, item);
|
||||
array->child->prev = item;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (child->next)
|
||||
{
|
||||
child = child->next;
|
||||
}
|
||||
suffix_object(child, item);
|
||||
array->child->prev = item;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -2202,6 +2203,12 @@ CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const it
|
||||
/* first element */
|
||||
parent->child = item->next;
|
||||
}
|
||||
else if (item->next == NULL)
|
||||
{
|
||||
/* last element */
|
||||
parent->child->prev = item->prev;
|
||||
}
|
||||
|
||||
/* make sure the detached item doesn't point anywhere anymore */
|
||||
item->prev = NULL;
|
||||
item->next = NULL;
|
||||
@@ -2299,6 +2306,10 @@ CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON
|
||||
}
|
||||
if (parent->child == item)
|
||||
{
|
||||
if (parent->child->prev == parent->child)
|
||||
{
|
||||
replacement->prev = replacement;
|
||||
}
|
||||
parent->child = replacement;
|
||||
}
|
||||
else
|
||||
@@ -2310,6 +2321,10 @@ CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON
|
||||
{
|
||||
replacement->prev->next = replacement;
|
||||
}
|
||||
if (replacement->next == NULL)
|
||||
{
|
||||
parent->child->prev = replacement;
|
||||
}
|
||||
}
|
||||
|
||||
item->next = NULL;
|
||||
@@ -2531,6 +2546,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count)
|
||||
}
|
||||
|
||||
a = cJSON_CreateArray();
|
||||
|
||||
for(i = 0; a && (i < (size_t)count); i++)
|
||||
{
|
||||
n = cJSON_CreateNumber(numbers[i]);
|
||||
@@ -2550,6 +2566,10 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count)
|
||||
p = n;
|
||||
}
|
||||
|
||||
if (a && a->child) {
|
||||
a->child->prev = n;
|
||||
}
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
@@ -2586,6 +2606,10 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count)
|
||||
p = n;
|
||||
}
|
||||
|
||||
if (a && a->child) {
|
||||
a->child->prev = n;
|
||||
}
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
@@ -2603,7 +2627,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count)
|
||||
|
||||
a = cJSON_CreateArray();
|
||||
|
||||
for(i = 0;a && (i < (size_t)count); i++)
|
||||
for(i = 0; a && (i < (size_t)count); i++)
|
||||
{
|
||||
n = cJSON_CreateNumber(numbers[i]);
|
||||
if(!n)
|
||||
@@ -2622,6 +2646,10 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count)
|
||||
p = n;
|
||||
}
|
||||
|
||||
if (a && a->child) {
|
||||
a->child->prev = n;
|
||||
}
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
@@ -2658,6 +2686,10 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int co
|
||||
p = n;
|
||||
}
|
||||
|
||||
if (a && a->child) {
|
||||
a->child->prev = n;
|
||||
}
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
@@ -2729,6 +2761,10 @@ CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse)
|
||||
}
|
||||
child = child->next;
|
||||
}
|
||||
if (newitem && newitem->child)
|
||||
{
|
||||
newitem->child->prev = newchild;
|
||||
}
|
||||
|
||||
return newitem;
|
||||
|
||||
@@ -2940,7 +2976,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item)
|
||||
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive)
|
||||
{
|
||||
if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF)) || cJSON_IsInvalid(a))
|
||||
if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
8
cJSON.h
8
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 13
|
||||
#define CJSON_VERSION_PATCH 15
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
@@ -176,8 +176,8 @@ CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *st
|
||||
CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void);
|
||||
|
||||
/* Check item type and return its value */
|
||||
CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item);
|
||||
CJSON_PUBLIC(double) cJSON_GetNumberValue(cJSON *item);
|
||||
CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item);
|
||||
CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item);
|
||||
|
||||
/* These functions check the type of an item */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item);
|
||||
@@ -256,7 +256,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * cons
|
||||
|
||||
/* 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,
|
||||
* but should point to a readable and writable adress area. */
|
||||
* but should point to a readable and writable address area. */
|
||||
CJSON_PUBLIC(void) cJSON_Minify(char *json);
|
||||
|
||||
/* Helper functions for creating and adding items to an object at the same time.
|
||||
|
||||
@@ -403,7 +403,7 @@ static cJSON *detach_item_from_array(cJSON *array, size_t which)
|
||||
/* item doesn't exist */
|
||||
return NULL;
|
||||
}
|
||||
if (c->prev)
|
||||
if (c != array->child)
|
||||
{
|
||||
/* not the first element */
|
||||
c->prev->next = c->next;
|
||||
@@ -412,10 +412,14 @@ static cJSON *detach_item_from_array(cJSON *array, size_t which)
|
||||
{
|
||||
c->next->prev = c->prev;
|
||||
}
|
||||
if (c==array->child)
|
||||
if (c == array->child)
|
||||
{
|
||||
array->child = c->next;
|
||||
}
|
||||
else if (c->next == NULL)
|
||||
{
|
||||
array->child->prev = c->prev;
|
||||
}
|
||||
/* make sure the detached item doesn't point anywhere anymore */
|
||||
c->prev = c->next = NULL;
|
||||
|
||||
@@ -956,7 +960,9 @@ static int apply_patch(cJSON *object, const cJSON *patch, const cJSON_bool case_
|
||||
|
||||
/* split pointer in parent and child */
|
||||
parent_pointer = cJSONUtils_strdup((unsigned char*)path->valuestring);
|
||||
child_pointer = (unsigned char*)strrchr((char*)parent_pointer, '/');
|
||||
if (parent_pointer) {
|
||||
child_pointer = (unsigned char*)strrchr((char*)parent_pointer, '/');
|
||||
}
|
||||
if (child_pointer != NULL)
|
||||
{
|
||||
child_pointer[0] = '\0';
|
||||
@@ -1402,6 +1408,10 @@ static cJSON *generate_merge_patch(cJSON * const from, cJSON * const to, const c
|
||||
from_child = from->child;
|
||||
to_child = to->child;
|
||||
patch = cJSON_CreateObject();
|
||||
if (patch == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
while (from_child || to_child)
|
||||
{
|
||||
int diff;
|
||||
|
||||
@@ -7,4 +7,4 @@ Description: Ultralightweight JSON parser in ANSI C
|
||||
URL: https://github.com/DaveGamble/cJSON
|
||||
Libs: -L${libdir} -lcjson
|
||||
Libs.private: -lm
|
||||
Cflags: -I${includedir}
|
||||
Cflags: -I${includedir} -I${includedir}/cjson
|
||||
|
||||
@@ -6,5 +6,5 @@ Version: @PROJECT_VERSION@
|
||||
Description: An implementation of JSON Pointer, Patch and Merge Patch based on cJSON.
|
||||
URL: https://github.com/DaveGamble/cJSON
|
||||
Libs: -L${libdir} -lcjson_utils
|
||||
Cflags: -I${includedir}
|
||||
Cflags: -I${includedir} -I${includedir}/cjson
|
||||
Requires: libcjson
|
||||
|
||||
@@ -117,6 +117,50 @@ static void cjson_add_true_should_fail_on_allocation_failure(void)
|
||||
cJSON_Delete(root);
|
||||
}
|
||||
|
||||
static void cjson_create_int_array_should_fail_on_allocation_failure(void)
|
||||
{
|
||||
int numbers[] = {1, 2, 3};
|
||||
|
||||
cJSON_InitHooks(&failing_hooks);
|
||||
|
||||
TEST_ASSERT_NULL(cJSON_CreateIntArray(numbers, 3));
|
||||
|
||||
cJSON_InitHooks(NULL);
|
||||
}
|
||||
|
||||
static void cjson_create_float_array_should_fail_on_allocation_failure(void)
|
||||
{
|
||||
float numbers[] = {1.0f, 2.0f, 3.0f};
|
||||
|
||||
cJSON_InitHooks(&failing_hooks);
|
||||
|
||||
TEST_ASSERT_NULL(cJSON_CreateFloatArray(numbers, 3));
|
||||
|
||||
cJSON_InitHooks(NULL);
|
||||
}
|
||||
|
||||
static void cjson_create_double_array_should_fail_on_allocation_failure(void)
|
||||
{
|
||||
double numbers[] = {1.0, 2.0, 3.0};
|
||||
|
||||
cJSON_InitHooks(&failing_hooks);
|
||||
|
||||
TEST_ASSERT_NULL(cJSON_CreateDoubleArray(numbers, 3));
|
||||
|
||||
cJSON_InitHooks(NULL);
|
||||
}
|
||||
|
||||
static void cjson_create_string_array_should_fail_on_allocation_failure(void)
|
||||
{
|
||||
const char* strings[] = {"1", "2", "3"};
|
||||
|
||||
cJSON_InitHooks(&failing_hooks);
|
||||
|
||||
TEST_ASSERT_NULL(cJSON_CreateStringArray(strings, 3));
|
||||
|
||||
cJSON_InitHooks(NULL);
|
||||
}
|
||||
|
||||
static void cjson_add_false_should_add_false(void)
|
||||
{
|
||||
cJSON *root = cJSON_CreateObject();
|
||||
@@ -390,6 +434,11 @@ int CJSON_CDECL main(void)
|
||||
RUN_TEST(cjson_add_true_should_fail_with_null_pointers);
|
||||
RUN_TEST(cjson_add_true_should_fail_on_allocation_failure);
|
||||
|
||||
RUN_TEST(cjson_create_int_array_should_fail_on_allocation_failure);
|
||||
RUN_TEST(cjson_create_float_array_should_fail_on_allocation_failure);
|
||||
RUN_TEST(cjson_create_double_array_should_fail_on_allocation_failure);
|
||||
RUN_TEST(cjson_create_string_array_should_fail_on_allocation_failure);
|
||||
|
||||
RUN_TEST(cjson_add_false_should_add_false);
|
||||
RUN_TEST(cjson_add_false_should_fail_with_null_pointers);
|
||||
RUN_TEST(cjson_add_false_should_fail_on_allocation_failure);
|
||||
|
||||
@@ -66,7 +66,7 @@ static cJSON_bool test_apply_patch(const cJSON * const test)
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Testing unkown\n");
|
||||
printf("Testing unknown\n");
|
||||
}
|
||||
|
||||
disabled = cJSON_GetObjectItemCaseSensitive(test, "disabled");
|
||||
|
||||
@@ -90,7 +90,8 @@ static void parse_array_should_parse_arrays_with_one_element(void)
|
||||
|
||||
assert_parse_array("[[]]");
|
||||
assert_has_child(item);
|
||||
assert_is_array(item->child);
|
||||
TEST_ASSERT_NOT_NULL(item->child);
|
||||
assert_has_type(item->child, cJSON_Array);
|
||||
assert_has_no_child(item->child);
|
||||
reset(item);
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ static char* create_monitor(void)
|
||||
goto end;
|
||||
}
|
||||
/* after creation was successful, immediately add it to the monitor,
|
||||
* thereby transfering ownership of the pointer to it */
|
||||
* thereby transferring ownership of the pointer to it */
|
||||
cJSON_AddItemToObject(monitor, "name", name);
|
||||
|
||||
resolutions = cJSON_CreateArray();
|
||||
|
||||
Reference in New Issue
Block a user