mirror of
https://github.com/DaveGamble/cJSON.git
synced 2026-11-14 19:03:32 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
87d8f0961a | ||
|
|
f66cbab4bf | ||
|
|
60ff122ef5 | ||
|
|
cb8693b058 | ||
|
|
545710e3bf | ||
|
|
543c28869e | ||
|
|
766dd9d590 | ||
|
|
b45f48e600 | ||
|
|
a6424b85dd | ||
|
|
3cecc40466 | ||
|
|
2fc55f6793 | ||
|
|
c7025b093a | ||
|
|
e7ebe77ebf | ||
|
|
61eb84d991 | ||
|
|
d321fa9e6e | ||
|
|
203a0dec6f | ||
|
|
c77a688927 | ||
|
|
e5dbaee131 | ||
|
|
189dcde644 | ||
|
|
b9eff8b02a | ||
|
|
f50dafc7d0 | ||
|
|
d348621ca9 | ||
|
|
744e47353a | ||
|
|
7795249dd4 | ||
|
|
324a6ac9a9 | ||
|
|
6ea4c01e4e | ||
|
|
9226e4ed8c | ||
|
|
7b6645794d | ||
|
|
4100379a04 | ||
|
|
2f6fc7f0f2 | ||
|
|
a1e1c208ff | ||
|
|
9bf4960cd5 | ||
|
|
488169faca | ||
|
|
9931900768 |
No files matched your search
@@ -6,3 +6,6 @@
|
|||||||
.github export-ignore
|
.github export-ignore
|
||||||
.editorconfig export-ignore
|
.editorconfig export-ignore
|
||||||
.travis.yml export-ignore
|
.travis.yml export-ignore
|
||||||
|
|
||||||
|
# Linguist incorrectly identified the headers as C++, manually override this.
|
||||||
|
*.h linguist-language=C
|
||||||
@@ -31,7 +31,7 @@ jobs:
|
|||||||
- name: install build dependencies
|
- name: install build dependencies
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
sudo apt-get install clang-8 valgrind
|
sudo apt-get install clang-14 valgrind
|
||||||
- name: build and test
|
- name: build and test
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
name: CIFuzz
|
||||||
|
on: [pull_request]
|
||||||
|
jobs:
|
||||||
|
Fuzzing:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Build Fuzzers
|
||||||
|
uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
|
||||||
|
with:
|
||||||
|
oss-fuzz-project-name: 'cjson'
|
||||||
|
dry-run: false
|
||||||
|
- name: Run Fuzzers
|
||||||
|
uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master
|
||||||
|
with:
|
||||||
|
oss-fuzz-project-name: 'cjson'
|
||||||
|
fuzz-seconds: 600
|
||||||
|
dry-run: false
|
||||||
|
- name: Upload Crash
|
||||||
|
uses: actions/upload-artifact@v1
|
||||||
|
if: failure()
|
||||||
|
with:
|
||||||
|
name: artifacts
|
||||||
|
path: ./out/artifacts
|
||||||
+3
-1
@@ -6,7 +6,7 @@ test
|
|||||||
*.swp
|
*.swp
|
||||||
*.patch
|
*.patch
|
||||||
tags
|
tags
|
||||||
*.dylib
|
*.dylib*
|
||||||
build/
|
build/
|
||||||
cJSON_test
|
cJSON_test
|
||||||
cJSON_test_utils
|
cJSON_test_utils
|
||||||
@@ -16,3 +16,5 @@ libcjson_utils.so.*
|
|||||||
.vscode
|
.vscode
|
||||||
.idea
|
.idea
|
||||||
cmake-build-debug
|
cmake-build-debug
|
||||||
|
*.lst
|
||||||
|
*.lss
|
||||||
@@ -1,3 +1,39 @@
|
|||||||
|
1.7.17 (Dec 26, 2023)
|
||||||
|
======
|
||||||
|
Fixes:
|
||||||
|
------
|
||||||
|
* Fix null reference in cJSON_SetValuestring(CVE-2023-50472), see #809
|
||||||
|
* Fix null reference in cJSON_InsertItemInArray(CVE-2023-50471), see #809 and #810
|
||||||
|
|
||||||
|
1.7.16 (Jul 5, 2023)
|
||||||
|
======
|
||||||
|
Features:
|
||||||
|
------
|
||||||
|
* Add an option for ENABLE_CJSON_VERSION_SO in CMakeLists.txt, see #534
|
||||||
|
* Add cmake_policy to CMakeLists.txt, see #163
|
||||||
|
* Add cJSON_SetBoolValue, see #639
|
||||||
|
* Add meson documentation, see #761
|
||||||
|
|
||||||
|
Fixes:
|
||||||
|
------
|
||||||
|
* Fix memory leak in merge_patch, see #611
|
||||||
|
* Fix conflicting target names 'uninstall', see #617
|
||||||
|
* Bump cmake version to 3.0 and use new version syntax, see #587
|
||||||
|
* Print int without decimal places, see #630
|
||||||
|
* Fix 'cjson_utils-static' target not exist, see #625
|
||||||
|
* Add allocate check for replace_item_in_object, see #675
|
||||||
|
* Fix a null pointer crash in cJSON_ReplaceItemViaPointer, see #726
|
||||||
|
|
||||||
|
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)
|
1.7.14 (Sep 3, 2020)
|
||||||
======
|
======
|
||||||
Fixes:
|
Fixes:
|
||||||
|
|||||||
+26
-10
@@ -1,17 +1,16 @@
|
|||||||
set(CMAKE_LEGACY_CYGWIN_WIN32 0)
|
set(CMAKE_LEGACY_CYGWIN_WIN32 0)
|
||||||
cmake_minimum_required(VERSION 2.8.5)
|
cmake_minimum_required(VERSION 3.0)
|
||||||
|
|
||||||
project(cJSON C)
|
project(cJSON
|
||||||
|
VERSION 1.7.17
|
||||||
|
LANGUAGES C)
|
||||||
|
|
||||||
|
cmake_policy(SET CMP0054 NEW) # set CMP0054 policy
|
||||||
|
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
set(PROJECT_VERSION_MAJOR 1)
|
|
||||||
set(PROJECT_VERSION_MINOR 7)
|
|
||||||
set(PROJECT_VERSION_PATCH 14)
|
|
||||||
set(CJSON_VERSION_SO 1)
|
set(CJSON_VERSION_SO 1)
|
||||||
set(CJSON_UTILS_VERSION_SO 1)
|
set(CJSON_UTILS_VERSION_SO 1)
|
||||||
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
|
|
||||||
|
|
||||||
|
|
||||||
set(custom_compiler_flags)
|
set(custom_compiler_flags)
|
||||||
|
|
||||||
@@ -122,6 +121,7 @@ set(SOURCES cJSON.c)
|
|||||||
option(BUILD_SHARED_AND_STATIC_LIBS "Build both shared and static libraries" Off)
|
option(BUILD_SHARED_AND_STATIC_LIBS "Build both shared and static libraries" Off)
|
||||||
option(CJSON_OVERRIDE_BUILD_SHARED_LIBS "Override BUILD_SHARED_LIBS with CJSON_BUILD_SHARED_LIBS" OFF)
|
option(CJSON_OVERRIDE_BUILD_SHARED_LIBS "Override BUILD_SHARED_LIBS with CJSON_BUILD_SHARED_LIBS" OFF)
|
||||||
option(CJSON_BUILD_SHARED_LIBS "Overrides BUILD_SHARED_LIBS if CJSON_OVERRIDE_BUILD_SHARED_LIBS is enabled" ON)
|
option(CJSON_BUILD_SHARED_LIBS "Overrides BUILD_SHARED_LIBS if CJSON_OVERRIDE_BUILD_SHARED_LIBS is enabled" ON)
|
||||||
|
option(ENABLE_CJSON_VERSION_SO "Enables cJSON so version" ON)
|
||||||
|
|
||||||
if ((CJSON_OVERRIDE_BUILD_SHARED_LIBS AND CJSON_BUILD_SHARED_LIBS) OR ((NOT CJSON_OVERRIDE_BUILD_SHARED_LIBS) AND BUILD_SHARED_LIBS))
|
if ((CJSON_OVERRIDE_BUILD_SHARED_LIBS AND CJSON_BUILD_SHARED_LIBS) OR ((NOT CJSON_OVERRIDE_BUILD_SHARED_LIBS) AND BUILD_SHARED_LIBS))
|
||||||
set(CJSON_LIBRARY_TYPE SHARED)
|
set(CJSON_LIBRARY_TYPE SHARED)
|
||||||
@@ -156,17 +156,23 @@ install(TARGETS "${CJSON_LIB}"
|
|||||||
INCLUDES DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}"
|
INCLUDES DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}"
|
||||||
)
|
)
|
||||||
if (BUILD_SHARED_AND_STATIC_LIBS)
|
if (BUILD_SHARED_AND_STATIC_LIBS)
|
||||||
install(TARGETS "${CJSON_LIB}-static" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}")
|
install(TARGETS "${CJSON_LIB}-static"
|
||||||
|
EXPORT "${CJSON_LIB}"
|
||||||
|
ARCHIVE DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}"
|
||||||
|
INCLUDES DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}"
|
||||||
|
)
|
||||||
endif()
|
endif()
|
||||||
if(ENABLE_TARGET_EXPORT)
|
if(ENABLE_TARGET_EXPORT)
|
||||||
# export library information for CMake projects
|
# export library information for CMake projects
|
||||||
install(EXPORT "${CJSON_LIB}" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/cJSON")
|
install(EXPORT "${CJSON_LIB}" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/cJSON")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(ENABLE_CJSON_VERSION_SO)
|
||||||
set_target_properties("${CJSON_LIB}"
|
set_target_properties("${CJSON_LIB}"
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
SOVERSION "${CJSON_VERSION_SO}"
|
SOVERSION "${CJSON_VERSION_SO}"
|
||||||
VERSION "${PROJECT_VERSION}")
|
VERSION "${PROJECT_VERSION}")
|
||||||
|
endif()
|
||||||
|
|
||||||
#cJSON_Utils
|
#cJSON_Utils
|
||||||
option(ENABLE_CJSON_UTILS "Enable building the cJSON_Utils library." OFF)
|
option(ENABLE_CJSON_UTILS "Enable building the cJSON_Utils library." OFF)
|
||||||
@@ -199,7 +205,11 @@ if(ENABLE_CJSON_UTILS)
|
|||||||
INCLUDES DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}"
|
INCLUDES DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}"
|
||||||
)
|
)
|
||||||
if (BUILD_SHARED_AND_STATIC_LIBS)
|
if (BUILD_SHARED_AND_STATIC_LIBS)
|
||||||
install(TARGETS "${CJSON_UTILS_LIB}-static" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}")
|
install(TARGETS "${CJSON_UTILS_LIB}-static"
|
||||||
|
EXPORT "${CJSON_UTILS_LIB}"
|
||||||
|
ARCHIVE DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}"
|
||||||
|
INCLUDES DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}"
|
||||||
|
)
|
||||||
endif()
|
endif()
|
||||||
install(FILES cJSON_Utils.h DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}/cjson")
|
install(FILES cJSON_Utils.h DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}/cjson")
|
||||||
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcjson_utils.pc" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig")
|
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcjson_utils.pc" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig")
|
||||||
@@ -208,11 +218,13 @@ if(ENABLE_CJSON_UTILS)
|
|||||||
install(EXPORT "${CJSON_UTILS_LIB}" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/cJSON")
|
install(EXPORT "${CJSON_UTILS_LIB}" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/cJSON")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(ENABLE_CJSON_VERSION_SO)
|
||||||
set_target_properties("${CJSON_UTILS_LIB}"
|
set_target_properties("${CJSON_UTILS_LIB}"
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
SOVERSION "${CJSON_UTILS_VERSION_SO}"
|
SOVERSION "${CJSON_UTILS_VERSION_SO}"
|
||||||
VERSION "${PROJECT_VERSION}")
|
VERSION "${PROJECT_VERSION}")
|
||||||
endif()
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
# create the other package config files
|
# create the other package config files
|
||||||
configure_file(
|
configure_file(
|
||||||
@@ -255,7 +267,11 @@ if(ENABLE_CJSON_TEST)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
#Create the uninstall target
|
#Create the uninstall target
|
||||||
add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${PROJECT_SOURCE_DIR}/library_config/uninstall.cmake")
|
option(ENABLE_CJSON_UNINSTALL "Enable creating uninstall target" ON)
|
||||||
|
if(ENABLE_CJSON_UNINSTALL)
|
||||||
|
add_custom_target(uninstall "${CMAKE_COMMAND}" -P
|
||||||
|
"${PROJECT_SOURCE_DIR}/library_config/uninstall.cmake")
|
||||||
|
endif()
|
||||||
|
|
||||||
# Enable the use of locales
|
# Enable the use of locales
|
||||||
option(ENABLE_LOCALES "Enable the use of locales" ON)
|
option(ENABLE_LOCALES "Enable the use of locales" ON)
|
||||||
|
|||||||
@@ -10,8 +10,10 @@ Current Maintainer:
|
|||||||
|
|
||||||
Contributors:
|
Contributors:
|
||||||
* [Ajay Bhargav](https://github.com/ajaybhargav)
|
* [Ajay Bhargav](https://github.com/ajaybhargav)
|
||||||
|
* [AlexanderVasiljev](https://github.com/AlexanderVasiljev)
|
||||||
* [Alper Akcan](https://github.com/alperakcan)
|
* [Alper Akcan](https://github.com/alperakcan)
|
||||||
* [Andrew Tang](https://github.com/singku)
|
* [Andrew Tang](https://github.com/singku)
|
||||||
|
* [Andy](https://github.com/mlh0101)
|
||||||
* [Anton Sergeev](https://github.com/anton-sergeev)
|
* [Anton Sergeev](https://github.com/anton-sergeev)
|
||||||
* [Benbuck Nason](https://github.com/bnason-nf)
|
* [Benbuck Nason](https://github.com/bnason-nf)
|
||||||
* [Bernt Johan Damslora](https://github.com/bjda)
|
* [Bernt Johan Damslora](https://github.com/bjda)
|
||||||
@@ -29,20 +31,25 @@ Contributors:
|
|||||||
* [Fabrice Fontaine](https://github.com/ffontaine)
|
* [Fabrice Fontaine](https://github.com/ffontaine)
|
||||||
* Ian Mobley
|
* Ian Mobley
|
||||||
* Irwan Djadjadi
|
* Irwan Djadjadi
|
||||||
|
* [hopper-vul](https://github.com/hopper-vul)
|
||||||
* [HuKeping](https://github.com/HuKeping)
|
* [HuKeping](https://github.com/HuKeping)
|
||||||
* [IvanVoid](https://github.com/npi3pak)
|
* [IvanVoid](https://github.com/npi3pak)
|
||||||
* [Jakub Wilk](https://github.com/jwilk)
|
* [Jakub Wilk](https://github.com/jwilk)
|
||||||
* [Jiri Zouhar](https://github.com/loigu)
|
* [Jiri Zouhar](https://github.com/loigu)
|
||||||
* [Jonathan Fether](https://github.com/jfether)
|
* [Jonathan Fether](https://github.com/jfether)
|
||||||
|
* [Joshua Arulsamy](https://github.com/jarulsamy)
|
||||||
* [Julian Ste](https://github.com/julian-st)
|
* [Julian Ste](https://github.com/julian-st)
|
||||||
* [Julián Vásquez](https://github.com/juvasquezg)
|
* [Julián Vásquez](https://github.com/juvasquezg)
|
||||||
|
* [Junbo Zheng](https://github.com/Junbo-Zheng)
|
||||||
* [Kevin Branigan](https://github.com/kbranigan)
|
* [Kevin Branigan](https://github.com/kbranigan)
|
||||||
* [Kevin Sapper](https://github.com/sappo)
|
* [Kevin Sapper](https://github.com/sappo)
|
||||||
* [Kyle Chisholm](https://github.com/ChisholmKyle)
|
* [Kyle Chisholm](https://github.com/ChisholmKyle)
|
||||||
* [Linus Wallgren](https://github.com/ecksun)
|
* [Linus Wallgren](https://github.com/ecksun)
|
||||||
|
* [MaxBrandtner](https://github.com/MaxBrandtner)
|
||||||
* [Mateusz Szafoni](https://github.com/raiden00pl)
|
* [Mateusz Szafoni](https://github.com/raiden00pl)
|
||||||
* Mike Pontillo
|
* Mike Pontillo
|
||||||
* [miaoerduo](https://github.com/miaoerduo)
|
* [miaoerduo](https://github.com/miaoerduo)
|
||||||
|
* [mohawk2](https://github.com/mohawk2)
|
||||||
* [Mike Jerris](https://github.com/mjerris)
|
* [Mike Jerris](https://github.com/mjerris)
|
||||||
* [Mike Robinson](https://github.com/mhrobinson)
|
* [Mike Robinson](https://github.com/mhrobinson)
|
||||||
* [Moorthy](https://github.com/moorthy-bs)
|
* [Moorthy](https://github.com/moorthy-bs)
|
||||||
@@ -61,10 +68,14 @@ Contributors:
|
|||||||
* [Romain Porte](https://github.com/MicroJoe)
|
* [Romain Porte](https://github.com/MicroJoe)
|
||||||
* [SANJEEV BA](https://github.com/basanjeev)
|
* [SANJEEV BA](https://github.com/basanjeev)
|
||||||
* [Sang-Heon Jeon](https://github.com/lntuition)
|
* [Sang-Heon Jeon](https://github.com/lntuition)
|
||||||
|
* [Sayan Bandyopadhyay](https://github.com/saynb)
|
||||||
* [Simon Sobisch](https://github.com/GitMensch)
|
* [Simon Sobisch](https://github.com/GitMensch)
|
||||||
* [Simon Ricaldone](https://github.com/simon-p-r)
|
* [Simon Ricaldone](https://github.com/simon-p-r)
|
||||||
|
* [Stoian Ivanov](https://github.com/sdrsdr)
|
||||||
|
* [SuperH-0630](https://github.com/SuperH-0630)
|
||||||
* [Square789](https://github.com/Square789)
|
* [Square789](https://github.com/Square789)
|
||||||
* [Stephan Gatzka](https://github.com/gatzka)
|
* [Stephan Gatzka](https://github.com/gatzka)
|
||||||
|
* [Tony Langhammer](https://github.com/BigBrainAFK)
|
||||||
* [Vemake](https://github.com/vemakereporter)
|
* [Vemake](https://github.com/vemakereporter)
|
||||||
* [Wei Tan](https://github.com/tan-wei)
|
* [Wei Tan](https://github.com/tan-wei)
|
||||||
* [Weston Schmidt](https://github.com/schmidtw)
|
* [Weston Schmidt](https://github.com/schmidtw)
|
||||||
@@ -73,6 +84,7 @@ Contributors:
|
|||||||
* [yuta-oxo](https://github.com/yuta-oxo)
|
* [yuta-oxo](https://github.com/yuta-oxo)
|
||||||
* [Zach Hindes](https://github.com/zhindes)
|
* [Zach Hindes](https://github.com/zhindes)
|
||||||
* [Zhao Zhixu](https://github.com/zhaozhixu)
|
* [Zhao Zhixu](https://github.com/zhaozhixu)
|
||||||
|
* [10km](https://github.com/10km)
|
||||||
|
|
||||||
And probably more people on [SourceForge](https://sourceforge.net/p/cjson/bugs/search/?q=status%3Aclosed-rejected+or+status%3Aclosed-out-of-date+or+status%3Awont-fix+or+status%3Aclosed-fixed+or+status%3Aclosed&page=0)
|
And probably more people on [SourceForge](https://sourceforge.net/p/cjson/bugs/search/?q=status%3Aclosed-rejected+or+status%3Aclosed-out-of-date+or+status%3Awont-fix+or+status%3Aclosed-fixed+or+status%3Aclosed&page=0)
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ CJSON_TEST_SRC = cJSON.c test.c
|
|||||||
|
|
||||||
LDLIBS = -lm
|
LDLIBS = -lm
|
||||||
|
|
||||||
LIBVERSION = 1.7.14
|
LIBVERSION = 1.7.17
|
||||||
CJSON_SOVERSION = 1
|
CJSON_SOVERSION = 1
|
||||||
UTILS_SOVERSION = 1
|
UTILS_SOVERSION = 1
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ Ultralightweight JSON parser in ANSI C.
|
|||||||
* [Copying the source](#copying-the-source)
|
* [Copying the source](#copying-the-source)
|
||||||
* [CMake](#cmake)
|
* [CMake](#cmake)
|
||||||
* [Makefile](#makefile)
|
* [Makefile](#makefile)
|
||||||
|
* [Meson](#meson)
|
||||||
* [Vcpkg](#Vcpkg)
|
* [Vcpkg](#Vcpkg)
|
||||||
* [Including cJSON](#including-cjson)
|
* [Including cJSON](#including-cjson)
|
||||||
* [Data Structure](#data-structure)
|
* [Data Structure](#data-structure)
|
||||||
@@ -118,6 +119,7 @@ You can change the build process with a list of different options that you can p
|
|||||||
* `-DCMAKE_INSTALL_PREFIX=/usr`: Set a prefix for the installation.
|
* `-DCMAKE_INSTALL_PREFIX=/usr`: Set a prefix for the installation.
|
||||||
* `-DENABLE_LOCALES=On`: Enable the usage of localeconv method. ( on by default )
|
* `-DENABLE_LOCALES=On`: Enable the usage of localeconv method. ( on by default )
|
||||||
* `-DCJSON_OVERRIDE_BUILD_SHARED_LIBS=On`: Enable overriding the value of `BUILD_SHARED_LIBS` with `-DCJSON_BUILD_SHARED_LIBS`.
|
* `-DCJSON_OVERRIDE_BUILD_SHARED_LIBS=On`: Enable overriding the value of `BUILD_SHARED_LIBS` with `-DCJSON_BUILD_SHARED_LIBS`.
|
||||||
|
* `-DENABLE_CJSON_VERSION_SO`: Enable cJSON so version. ( on by default )
|
||||||
|
|
||||||
If you are packaging cJSON for a distribution of Linux, you would probably take these steps for example:
|
If you are packaging cJSON for a distribution of Linux, you would probably take these steps for example:
|
||||||
```
|
```
|
||||||
@@ -144,6 +146,23 @@ make all
|
|||||||
|
|
||||||
If you want, you can install the compiled library to your system using `make install`. By default it will install the headers in `/usr/local/include/cjson` and the libraries in `/usr/local/lib`. But you can change this behavior by setting the `PREFIX` and `DESTDIR` variables: `make PREFIX=/usr DESTDIR=temp install`. And uninstall them with: `make PREFIX=/usr DESTDIR=temp uninstall`.
|
If you want, you can install the compiled library to your system using `make install`. By default it will install the headers in `/usr/local/include/cjson` and the libraries in `/usr/local/lib`. But you can change this behavior by setting the `PREFIX` and `DESTDIR` variables: `make PREFIX=/usr DESTDIR=temp install`. And uninstall them with: `make PREFIX=/usr DESTDIR=temp uninstall`.
|
||||||
|
|
||||||
|
#### Meson
|
||||||
|
|
||||||
|
To make cjson work in a project using meson, the libcjson dependency has to be included:
|
||||||
|
|
||||||
|
```meson
|
||||||
|
project('c-json-example', 'c')
|
||||||
|
|
||||||
|
cjson = dependency('libcjson')
|
||||||
|
|
||||||
|
example = executable(
|
||||||
|
'example',
|
||||||
|
'example.c',
|
||||||
|
dependencies: [cjson],
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
#### Vcpkg
|
#### Vcpkg
|
||||||
|
|
||||||
You can download and install cJSON using the [vcpkg](https://github.com/Microsoft/vcpkg) dependency manager:
|
You can download and install cJSON using the [vcpkg](https://github.com/Microsoft/vcpkg) dependency manager:
|
||||||
@@ -406,7 +425,7 @@ end:
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Alternatively we can use the `cJSON_Add...ToObject` helper functions to make our lifes a little easier:
|
Alternatively we can use the `cJSON_Add...ToObject` helper functions to make our lives a little easier:
|
||||||
|
|
||||||
```c
|
```c
|
||||||
//NOTE: Returns a heap allocated string, you are required to free it after use.
|
//NOTE: Returns a heap allocated string, you are required to free it after use.
|
||||||
|
|||||||
@@ -78,8 +78,12 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef NAN
|
#ifndef NAN
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define NAN sqrt(-1.0)
|
||||||
|
#else
|
||||||
#define NAN 0.0/0.0
|
#define NAN 0.0/0.0
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const unsigned char *json;
|
const unsigned char *json;
|
||||||
@@ -113,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 */
|
/* 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 != 14)
|
#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 17)
|
||||||
#error cJSON.h and cJSON.c have different versions. Make sure that both have the same.
|
#error cJSON.h and cJSON.c have different versions. Make sure that both have the same.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -397,7 +401,12 @@ CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring)
|
|||||||
{
|
{
|
||||||
char *copy = NULL;
|
char *copy = NULL;
|
||||||
/* if object's type is not cJSON_String or is cJSON_IsReference, it should not set valuestring */
|
/* if object's type is not cJSON_String or is cJSON_IsReference, it should not set valuestring */
|
||||||
if (!(object->type & cJSON_String) || (object->type & cJSON_IsReference))
|
if ((object == NULL) || !(object->type & cJSON_String) || (object->type & cJSON_IsReference))
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
/* return NULL if the object is corrupted */
|
||||||
|
if (object->valuestring == NULL)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -507,10 +516,8 @@ static unsigned char* ensure(printbuffer * const p, size_t needed)
|
|||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (newbuffer)
|
|
||||||
{
|
|
||||||
memcpy(newbuffer, p->buffer, p->offset + 1);
|
memcpy(newbuffer, p->buffer, p->offset + 1);
|
||||||
}
|
|
||||||
p->hooks.deallocate(p->buffer);
|
p->hooks.deallocate(p->buffer);
|
||||||
}
|
}
|
||||||
p->length = newsize;
|
p->length = newsize;
|
||||||
@@ -560,6 +567,10 @@ static cJSON_bool print_number(const cJSON * const item, printbuffer * const out
|
|||||||
{
|
{
|
||||||
length = sprintf((char*)number_buffer, "null");
|
length = sprintf((char*)number_buffer, "null");
|
||||||
}
|
}
|
||||||
|
else if(d == (double)item->valueint)
|
||||||
|
{
|
||||||
|
length = sprintf((char*)number_buffer, "%d", item->valueint);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Try 15 decimal places of precision to avoid nonsignificant nonzero digits */
|
/* Try 15 decimal places of precision to avoid nonsignificant nonzero digits */
|
||||||
@@ -2258,7 +2269,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON
|
|||||||
{
|
{
|
||||||
cJSON *after_inserted = NULL;
|
cJSON *after_inserted = NULL;
|
||||||
|
|
||||||
if (which < 0)
|
if (which < 0 || newitem == NULL)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -2269,6 +2280,11 @@ CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON
|
|||||||
return add_item_to_array(array, newitem);
|
return add_item_to_array(array, newitem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (after_inserted != array->child && after_inserted->prev == NULL) {
|
||||||
|
/* return false if after_inserted is a corrupted array item */
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
newitem->next = after_inserted;
|
newitem->next = after_inserted;
|
||||||
newitem->prev = after_inserted->prev;
|
newitem->prev = after_inserted->prev;
|
||||||
after_inserted->prev = newitem;
|
after_inserted->prev = newitem;
|
||||||
@@ -2285,7 +2301,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON
|
|||||||
|
|
||||||
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement)
|
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement)
|
||||||
{
|
{
|
||||||
if ((parent == NULL) || (replacement == NULL) || (item == NULL))
|
if ((parent == NULL) || (parent->child == NULL) || (replacement == NULL) || (item == NULL))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -2355,6 +2371,11 @@ static cJSON_bool replace_item_in_object(cJSON *object, const char *string, cJSO
|
|||||||
cJSON_free(replacement->string);
|
cJSON_free(replacement->string);
|
||||||
}
|
}
|
||||||
replacement->string = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks);
|
replacement->string = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks);
|
||||||
|
if (replacement->string == NULL)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
replacement->type &= ~cJSON_StringIsConst;
|
replacement->type &= ~cJSON_StringIsConst;
|
||||||
|
|
||||||
return cJSON_ReplaceItemViaPointer(object, get_object_item(object, string, case_sensitive), replacement);
|
return cJSON_ReplaceItemViaPointer(object, get_object_item(object, string, case_sensitive), replacement);
|
||||||
@@ -2544,6 +2565,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count)
|
|||||||
}
|
}
|
||||||
|
|
||||||
a = cJSON_CreateArray();
|
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]);
|
n = cJSON_CreateNumber(numbers[i]);
|
||||||
@@ -2562,7 +2584,10 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count)
|
|||||||
}
|
}
|
||||||
p = n;
|
p = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (a && a->child) {
|
||||||
a->child->prev = n;
|
a->child->prev = n;
|
||||||
|
}
|
||||||
|
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
@@ -2599,7 +2624,10 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count)
|
|||||||
}
|
}
|
||||||
p = n;
|
p = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (a && a->child) {
|
||||||
a->child->prev = n;
|
a->child->prev = n;
|
||||||
|
}
|
||||||
|
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
@@ -2636,7 +2664,10 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count)
|
|||||||
}
|
}
|
||||||
p = n;
|
p = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (a && a->child) {
|
||||||
a->child->prev = n;
|
a->child->prev = n;
|
||||||
|
}
|
||||||
|
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
@@ -2673,7 +2704,10 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int co
|
|||||||
}
|
}
|
||||||
p = n;
|
p = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (a && a->child) {
|
||||||
a->child->prev = n;
|
a->child->prev = n;
|
||||||
|
}
|
||||||
|
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
@@ -2961,7 +2995,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)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJ
|
|||||||
/* project version */
|
/* project version */
|
||||||
#define CJSON_VERSION_MAJOR 1
|
#define CJSON_VERSION_MAJOR 1
|
||||||
#define CJSON_VERSION_MINOR 7
|
#define CJSON_VERSION_MINOR 7
|
||||||
#define CJSON_VERSION_PATCH 14
|
#define CJSON_VERSION_PATCH 17
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
@@ -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.
|
/* 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,
|
* 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);
|
CJSON_PUBLIC(void) cJSON_Minify(char *json);
|
||||||
|
|
||||||
/* Helper functions for creating and adding items to an object at the same time.
|
/* Helper functions for creating and adding items to an object at the same time.
|
||||||
@@ -279,6 +279,13 @@ CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
|
|||||||
/* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */
|
/* 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);
|
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)->type=((object)->type &(~(cJSON_False|cJSON_True)))|((boolValue)?cJSON_True:cJSON_False) : \
|
||||||
|
cJSON_Invalid\
|
||||||
|
)
|
||||||
|
|
||||||
/* Macro for iterating over an array or object */
|
/* 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)
|
||||||
|
|
||||||
|
|||||||
@@ -960,7 +960,9 @@ static int apply_patch(cJSON *object, const cJSON *patch, const cJSON_bool case_
|
|||||||
|
|
||||||
/* split pointer in parent and child */
|
/* split pointer in parent and child */
|
||||||
parent_pointer = cJSONUtils_strdup((unsigned char*)path->valuestring);
|
parent_pointer = cJSONUtils_strdup((unsigned char*)path->valuestring);
|
||||||
|
if (parent_pointer) {
|
||||||
child_pointer = (unsigned char*)strrchr((char*)parent_pointer, '/');
|
child_pointer = (unsigned char*)strrchr((char*)parent_pointer, '/');
|
||||||
|
}
|
||||||
if (child_pointer != NULL)
|
if (child_pointer != NULL)
|
||||||
{
|
{
|
||||||
child_pointer[0] = '\0';
|
child_pointer[0] = '\0';
|
||||||
@@ -1365,6 +1367,7 @@ static cJSON *merge_patch(cJSON *target, const cJSON * const patch, const cJSON_
|
|||||||
replacement = merge_patch(replace_me, patch_child, case_sensitive);
|
replacement = merge_patch(replace_me, patch_child, case_sensitive);
|
||||||
if (replacement == NULL)
|
if (replacement == NULL)
|
||||||
{
|
{
|
||||||
|
cJSON_Delete(target);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1406,6 +1409,10 @@ static cJSON *generate_merge_patch(cJSON * const from, cJSON * const to, const c
|
|||||||
from_child = from->child;
|
from_child = from->child;
|
||||||
to_child = to->child;
|
to_child = to->child;
|
||||||
patch = cJSON_CreateObject();
|
patch = cJSON_CreateObject();
|
||||||
|
if (patch == NULL)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
while (from_child || to_child)
|
while (from_child || to_child)
|
||||||
{
|
{
|
||||||
int diff;
|
int diff;
|
||||||
|
|||||||
@@ -117,6 +117,50 @@ static void cjson_add_true_should_fail_on_allocation_failure(void)
|
|||||||
cJSON_Delete(root);
|
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)
|
static void cjson_add_false_should_add_false(void)
|
||||||
{
|
{
|
||||||
cJSON *root = cJSON_CreateObject();
|
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_with_null_pointers);
|
||||||
RUN_TEST(cjson_add_true_should_fail_on_allocation_failure);
|
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_add_false);
|
||||||
RUN_TEST(cjson_add_false_should_fail_with_null_pointers);
|
RUN_TEST(cjson_add_false_should_fail_with_null_pointers);
|
||||||
RUN_TEST(cjson_add_false_should_fail_on_allocation_failure);
|
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
|
else
|
||||||
{
|
{
|
||||||
printf("Testing unkown\n");
|
printf("Testing unknown\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
disabled = cJSON_GetObjectItemCaseSensitive(test, "disabled");
|
disabled = cJSON_GetObjectItemCaseSensitive(test, "disabled");
|
||||||
|
|||||||
+90
-8
@@ -28,7 +28,6 @@
|
|||||||
#include "unity/src/unity.h"
|
#include "unity/src/unity.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
|
|
||||||
static void cjson_array_foreach_should_loop_over_arrays(void)
|
static void cjson_array_foreach_should_loop_over_arrays(void)
|
||||||
{
|
{
|
||||||
cJSON array[1];
|
cJSON array[1];
|
||||||
@@ -77,7 +76,6 @@ static void cjson_get_object_item_should_get_object_items(void)
|
|||||||
found = cJSON_GetObjectItem(item, NULL);
|
found = cJSON_GetObjectItem(item, NULL);
|
||||||
TEST_ASSERT_NULL_MESSAGE(found, "Failed to fail on NULL string.");
|
TEST_ASSERT_NULL_MESSAGE(found, "Failed to fail on NULL string.");
|
||||||
|
|
||||||
|
|
||||||
found = cJSON_GetObjectItem(item, "one");
|
found = cJSON_GetObjectItem(item, "one");
|
||||||
TEST_ASSERT_NOT_NULL_MESSAGE(found, "Failed to find first item.");
|
TEST_ASSERT_NOT_NULL_MESSAGE(found, "Failed to find first item.");
|
||||||
TEST_ASSERT_EQUAL_DOUBLE(found->valuedouble, 1);
|
TEST_ASSERT_EQUAL_DOUBLE(found->valuedouble, 1);
|
||||||
@@ -127,7 +125,8 @@ static void cjson_get_object_item_case_sensitive_should_get_object_items(void)
|
|||||||
cJSON_Delete(item);
|
cJSON_Delete(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cjson_get_object_item_should_not_crash_with_array(void) {
|
static void cjson_get_object_item_should_not_crash_with_array(void)
|
||||||
|
{
|
||||||
cJSON *array = NULL;
|
cJSON *array = NULL;
|
||||||
cJSON *found = NULL;
|
cJSON *found = NULL;
|
||||||
array = cJSON_Parse("[1]");
|
array = cJSON_Parse("[1]");
|
||||||
@@ -138,7 +137,8 @@ static void cjson_get_object_item_should_not_crash_with_array(void) {
|
|||||||
cJSON_Delete(array);
|
cJSON_Delete(array);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cjson_get_object_item_case_sensitive_should_not_crash_with_array(void) {
|
static void cjson_get_object_item_case_sensitive_should_not_crash_with_array(void)
|
||||||
|
{
|
||||||
cJSON *array = NULL;
|
cJSON *array = NULL;
|
||||||
cJSON *found = NULL;
|
cJSON *found = NULL;
|
||||||
array = cJSON_Parse("[1]");
|
array = cJSON_Parse("[1]");
|
||||||
@@ -302,7 +302,6 @@ static void cjson_replace_item_via_pointer_should_replace_items(void)
|
|||||||
cJSON_AddItemToArray(array, middle);
|
cJSON_AddItemToArray(array, middle);
|
||||||
cJSON_AddItemToArray(array, end);
|
cJSON_AddItemToArray(array, end);
|
||||||
|
|
||||||
|
|
||||||
memset(replacements, '\0', sizeof(replacements));
|
memset(replacements, '\0', sizeof(replacements));
|
||||||
|
|
||||||
/* replace beginning */
|
/* replace beginning */
|
||||||
@@ -353,6 +352,19 @@ static void cjson_functions_should_not_crash_with_null_pointers(void)
|
|||||||
{
|
{
|
||||||
char buffer[10];
|
char buffer[10];
|
||||||
cJSON *item = cJSON_CreateString("item");
|
cJSON *item = cJSON_CreateString("item");
|
||||||
|
cJSON *array = cJSON_CreateArray();
|
||||||
|
cJSON *item1 = cJSON_CreateString("item1");
|
||||||
|
cJSON *item2 = cJSON_CreateString("corrupted array item3");
|
||||||
|
cJSON *corruptedString = cJSON_CreateString("corrupted");
|
||||||
|
struct cJSON *originalPrev;
|
||||||
|
|
||||||
|
add_item_to_array(array, item1);
|
||||||
|
add_item_to_array(array, item2);
|
||||||
|
|
||||||
|
originalPrev = item2->prev;
|
||||||
|
item2->prev = NULL;
|
||||||
|
free(corruptedString->valuestring);
|
||||||
|
corruptedString->valuestring = NULL;
|
||||||
|
|
||||||
cJSON_InitHooks(NULL);
|
cJSON_InitHooks(NULL);
|
||||||
TEST_ASSERT_NULL(cJSON_Parse(NULL));
|
TEST_ASSERT_NULL(cJSON_Parse(NULL));
|
||||||
@@ -412,6 +424,8 @@ static void cjson_functions_should_not_crash_with_null_pointers(void)
|
|||||||
cJSON_DeleteItemFromObject(item, NULL);
|
cJSON_DeleteItemFromObject(item, NULL);
|
||||||
cJSON_DeleteItemFromObjectCaseSensitive(NULL, "item");
|
cJSON_DeleteItemFromObjectCaseSensitive(NULL, "item");
|
||||||
cJSON_DeleteItemFromObjectCaseSensitive(item, NULL);
|
cJSON_DeleteItemFromObjectCaseSensitive(item, NULL);
|
||||||
|
TEST_ASSERT_FALSE(cJSON_InsertItemInArray(array, 0, NULL));
|
||||||
|
TEST_ASSERT_FALSE(cJSON_InsertItemInArray(array, 1, item));
|
||||||
TEST_ASSERT_FALSE(cJSON_InsertItemInArray(NULL, 0, item));
|
TEST_ASSERT_FALSE(cJSON_InsertItemInArray(NULL, 0, item));
|
||||||
TEST_ASSERT_FALSE(cJSON_InsertItemInArray(item, 0, NULL));
|
TEST_ASSERT_FALSE(cJSON_InsertItemInArray(item, 0, NULL));
|
||||||
TEST_ASSERT_FALSE(cJSON_ReplaceItemViaPointer(NULL, item, item));
|
TEST_ASSERT_FALSE(cJSON_ReplaceItemViaPointer(NULL, item, item));
|
||||||
@@ -428,10 +442,16 @@ static void cjson_functions_should_not_crash_with_null_pointers(void)
|
|||||||
TEST_ASSERT_NULL(cJSON_Duplicate(NULL, true));
|
TEST_ASSERT_NULL(cJSON_Duplicate(NULL, true));
|
||||||
TEST_ASSERT_FALSE(cJSON_Compare(item, NULL, false));
|
TEST_ASSERT_FALSE(cJSON_Compare(item, NULL, false));
|
||||||
TEST_ASSERT_FALSE(cJSON_Compare(NULL, item, false));
|
TEST_ASSERT_FALSE(cJSON_Compare(NULL, item, false));
|
||||||
|
TEST_ASSERT_NULL(cJSON_SetValuestring(NULL, "test"));
|
||||||
|
TEST_ASSERT_NULL(cJSON_SetValuestring(corruptedString, "test"));
|
||||||
cJSON_Minify(NULL);
|
cJSON_Minify(NULL);
|
||||||
/* skipped because it is only used via a macro that checks for NULL */
|
/* skipped because it is only used via a macro that checks for NULL */
|
||||||
/* cJSON_SetNumberHelper(NULL, 0); */
|
/* cJSON_SetNumberHelper(NULL, 0); */
|
||||||
|
|
||||||
|
/* restore corrupted item2 to delete it */
|
||||||
|
item2->prev = originalPrev;
|
||||||
|
cJSON_Delete(corruptedString);
|
||||||
|
cJSON_Delete(array);
|
||||||
cJSON_Delete(item);
|
cJSON_Delete(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -501,7 +521,8 @@ static void cjson_get_number_value_should_get_a_number(void)
|
|||||||
cJSON_Delete(string);
|
cJSON_Delete(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cjson_create_string_reference_should_create_a_string_reference(void) {
|
static void cjson_create_string_reference_should_create_a_string_reference(void)
|
||||||
|
{
|
||||||
const char *string = "I am a string!";
|
const char *string = "I am a string!";
|
||||||
|
|
||||||
cJSON *string_reference = cJSON_CreateStringReference(string);
|
cJSON *string_reference = cJSON_CreateStringReference(string);
|
||||||
@@ -511,7 +532,8 @@ static void cjson_create_string_reference_should_create_a_string_reference(void)
|
|||||||
cJSON_Delete(string_reference);
|
cJSON_Delete(string_reference);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cjson_create_object_reference_should_create_an_object_reference(void) {
|
static void cjson_create_object_reference_should_create_an_object_reference(void)
|
||||||
|
{
|
||||||
cJSON *number_reference = NULL;
|
cJSON *number_reference = NULL;
|
||||||
cJSON *number_object = cJSON_CreateObject();
|
cJSON *number_object = cJSON_CreateObject();
|
||||||
cJSON *number = cJSON_CreateNumber(42);
|
cJSON *number = cJSON_CreateNumber(42);
|
||||||
@@ -529,7 +551,8 @@ static void cjson_create_object_reference_should_create_an_object_reference(void
|
|||||||
cJSON_Delete(number_reference);
|
cJSON_Delete(number_reference);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cjson_create_array_reference_should_create_an_array_reference(void) {
|
static void cjson_create_array_reference_should_create_an_array_reference(void)
|
||||||
|
{
|
||||||
cJSON *number_reference = NULL;
|
cJSON *number_reference = NULL;
|
||||||
cJSON *number_array = cJSON_CreateArray();
|
cJSON *number_array = cJSON_CreateArray();
|
||||||
cJSON *number = cJSON_CreateNumber(42);
|
cJSON *number = cJSON_CreateNumber(42);
|
||||||
@@ -650,6 +673,64 @@ static void cjson_set_valuestring_to_object_should_not_leak_memory(void)
|
|||||||
cJSON_Delete(root);
|
cJSON_Delete(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void cjson_set_bool_value_must_not_break_objects(void)
|
||||||
|
{
|
||||||
|
cJSON *bobj, *sobj, *oobj, *refobj = NULL;
|
||||||
|
|
||||||
|
TEST_ASSERT_TRUE((cJSON_SetBoolValue(refobj, 1) == cJSON_Invalid));
|
||||||
|
|
||||||
|
bobj = cJSON_CreateFalse();
|
||||||
|
TEST_ASSERT_TRUE(cJSON_IsFalse(bobj));
|
||||||
|
TEST_ASSERT_TRUE((cJSON_SetBoolValue(bobj, 1) == cJSON_True));
|
||||||
|
TEST_ASSERT_TRUE(cJSON_IsTrue(bobj));
|
||||||
|
cJSON_SetBoolValue(bobj, 1);
|
||||||
|
TEST_ASSERT_TRUE(cJSON_IsTrue(bobj));
|
||||||
|
TEST_ASSERT_TRUE((cJSON_SetBoolValue(bobj, 0) == cJSON_False));
|
||||||
|
TEST_ASSERT_TRUE(cJSON_IsFalse(bobj));
|
||||||
|
cJSON_SetBoolValue(bobj, 0);
|
||||||
|
TEST_ASSERT_TRUE(cJSON_IsFalse(bobj));
|
||||||
|
|
||||||
|
sobj = cJSON_CreateString("test");
|
||||||
|
TEST_ASSERT_TRUE(cJSON_IsString(sobj));
|
||||||
|
cJSON_SetBoolValue(sobj, 1);
|
||||||
|
TEST_ASSERT_TRUE(cJSON_IsString(sobj));
|
||||||
|
cJSON_SetBoolValue(sobj, 0);
|
||||||
|
TEST_ASSERT_TRUE(cJSON_IsString(sobj));
|
||||||
|
|
||||||
|
oobj = cJSON_CreateObject();
|
||||||
|
TEST_ASSERT_TRUE(cJSON_IsObject(oobj));
|
||||||
|
cJSON_SetBoolValue(oobj, 1);
|
||||||
|
TEST_ASSERT_TRUE(cJSON_IsObject(oobj));
|
||||||
|
cJSON_SetBoolValue(oobj, 0);
|
||||||
|
TEST_ASSERT_TRUE(cJSON_IsObject(oobj));
|
||||||
|
|
||||||
|
refobj = cJSON_CreateStringReference("conststring");
|
||||||
|
TEST_ASSERT_TRUE(cJSON_IsString(refobj));
|
||||||
|
TEST_ASSERT_TRUE(refobj->type & cJSON_IsReference);
|
||||||
|
cJSON_SetBoolValue(refobj, 1);
|
||||||
|
TEST_ASSERT_TRUE(cJSON_IsString(refobj));
|
||||||
|
TEST_ASSERT_TRUE(refobj->type & cJSON_IsReference);
|
||||||
|
cJSON_SetBoolValue(refobj, 0);
|
||||||
|
TEST_ASSERT_TRUE(cJSON_IsString(refobj));
|
||||||
|
TEST_ASSERT_TRUE(refobj->type & cJSON_IsReference);
|
||||||
|
cJSON_Delete(refobj);
|
||||||
|
|
||||||
|
refobj = cJSON_CreateObjectReference(oobj);
|
||||||
|
TEST_ASSERT_TRUE(cJSON_IsObject(refobj));
|
||||||
|
TEST_ASSERT_TRUE(refobj->type & cJSON_IsReference);
|
||||||
|
cJSON_SetBoolValue(refobj, 1);
|
||||||
|
TEST_ASSERT_TRUE(cJSON_IsObject(refobj));
|
||||||
|
TEST_ASSERT_TRUE(refobj->type & cJSON_IsReference);
|
||||||
|
cJSON_SetBoolValue(refobj, 0);
|
||||||
|
TEST_ASSERT_TRUE(cJSON_IsObject(refobj));
|
||||||
|
TEST_ASSERT_TRUE(refobj->type & cJSON_IsReference);
|
||||||
|
cJSON_Delete(refobj);
|
||||||
|
|
||||||
|
cJSON_Delete(oobj);
|
||||||
|
cJSON_Delete(bobj);
|
||||||
|
cJSON_Delete(sobj);
|
||||||
|
}
|
||||||
|
|
||||||
int CJSON_CDECL main(void)
|
int CJSON_CDECL main(void)
|
||||||
{
|
{
|
||||||
UNITY_BEGIN();
|
UNITY_BEGIN();
|
||||||
@@ -679,6 +760,7 @@ int CJSON_CDECL main(void)
|
|||||||
RUN_TEST(cjson_add_item_to_object_should_not_use_after_free_when_string_is_aliased);
|
RUN_TEST(cjson_add_item_to_object_should_not_use_after_free_when_string_is_aliased);
|
||||||
RUN_TEST(cjson_delete_item_from_array_should_not_broken_list_structure);
|
RUN_TEST(cjson_delete_item_from_array_should_not_broken_list_structure);
|
||||||
RUN_TEST(cjson_set_valuestring_to_object_should_not_leak_memory);
|
RUN_TEST(cjson_set_valuestring_to_object_should_not_leak_memory);
|
||||||
|
RUN_TEST(cjson_set_bool_value_must_not_break_objects);
|
||||||
|
|
||||||
return UNITY_END();
|
return UNITY_END();
|
||||||
}
|
}
|
||||||
@@ -69,7 +69,7 @@ static char* create_monitor(void)
|
|||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
/* after creation was successful, immediately add it to the monitor,
|
/* 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);
|
cJSON_AddItemToObject(monitor, "name", name);
|
||||||
|
|
||||||
resolutions = cJSON_CreateArray();
|
resolutions = cJSON_CreateArray();
|
||||||
|
|||||||
Reference in new issue
Block a user