···11-1.7.12
11+1.7.15 (Aug 25, 2021)
22======
33Fixes:
44------
55-* Fix infinite loop in `cJSON_Minify` (potential Denial of Service), thanks @Alanscut for reporting. See #354
66-* Fix link error for Visual Studio. Thanks @tan-wei, see #352
77-* Undefine `true` and `false` for `cJSON_Utils` before redefining them. Thanks @raiden00pl, see #347
55+* Fix potential core dumped for strrchr, see [#546](https://github.com/DaveGamble/cJSON/pull/546)
66+* Fix null pointer crash in cJSON_CreateXxArray, see [#538](https://github.com/DaveGamble/cJSON/pull/538)
77+* Fix several null pointer problems on allocation failure, see [#526](https://github.com/DaveGamble/cJSON/pull/526)
88+* Fix a possible dereference of null pointer, see [#519](https://github.com/DaveGamble/cJSON/pull/519)
99+* Fix windows build failure about defining nan, see [#518](https://github.com/DaveGamble/cJSON/pull/518)
8101111+1.7.14 (Sep 3, 2020)
1212+======
1313+Fixes:
1414+------
1515+* optimize the way to find tail node, see [#503](https://github.com/DaveGamble/cJSON/pull/503)
1616+* Fix WError error on macosx because NAN is a float. Thanks @sappo, see [#484](https://github.com/DaveGamble/cJSON/pull/484)
1717+* Fix some bugs in detach and replace. Thanks @miaoerduo, see [#456](https://github.com/DaveGamble/cJSON/pull/456)
9181010-1.7.11
1919+1.7.13 (Apr 2, 2020)
1120======
2121+Features:
2222+---------
2323+* add new API of cJSON_ParseWithLength without breaking changes. Thanks @caglarivriz, see [#358](https://github.com/DaveGamble/cJSON/pull/358)
2424+* add new API of cJSON_GetNumberValue. Thanks @Intuition, see[#385](https://github.com/DaveGamble/cJSON/pull/385)
2525+* add uninstall target function for CMake. See [#402](https://github.com/DaveGamble/cJSON/pull/402)
2626+* Improve performance of adding item to array. Thanks @xiaomianhehe, see [#430](https://github.com/DaveGamble/cJSON/pull/430), [#448](https://github.com/DaveGamble/cJSON/pull/448)
2727+* add new API of cJSON_SetValuestring, for changing the valuestring safely. See [#451](https://github.com/DaveGamble/cJSON/pull/451)
2828+* add return value for cJSON_AddItemTo... and cJSON_ReplaceItem... (check if the operation successful). See [#453](https://github.com/DaveGamble/cJSON/pull/453)
2929+1230Fixes:
1331------
1414-* Fix a bug where cJSON_Minify could overflow it's buffer, both reading and writing. This is a security issue. (see #338). Big thanks @bigric3 for reporting.
1515-* Unset `true` and `false` macros before setting them if they exist. See #339, thanks @raiden00pl for reporting
3232+* Fix clang -Wfloat-equal warning. Thanks @paulmalovanyi, see [#368](https://github.com/DaveGamble/cJSON/pull/368)
3333+* Fix make failed in mac os. See [#405](https://github.com/DaveGamble/cJSON/pull/405)
3434+* Fix memory leak in cJSONUtils_FindPointerFromObjectTo. Thanks @andywolk for reporting, see [#414](https://github.com/DaveGamble/cJSON/issues/414)
3535+* Fix bug in encode_string_as_pointer. Thanks @AIChangJiang for reporting, see [#439](https://github.com/DaveGamble/cJSON/issues/439)
16361717-1.7.10
3737+1.7.12 (May 17, 2019)
1838======
1939Fixes:
2040------
2121-* Fix package config file for `libcjson`. Thanks @shiluotang for reporting (#321)
2222-* Correctly split lists in `cJSON_Utils`'s merge sort. Thanks @andysCaplin for the fix (#322)
4141+* Fix infinite loop in `cJSON_Minify` (potential Denial of Service). Thanks @Alanscut for reporting, see [#354](https://github.com/DaveGamble/cJSON/issues/354)
4242+* Fix link error for Visual Studio. Thanks @tan-wei, see [#352](https://github.com/DaveGamble/cJSON/pull/352).
4343+* Undefine `true` and `false` for `cJSON_Utils` before redefining them. Thanks @raiden00pl, see [#347](https://github.com/DaveGamble/cJSON/pull/347).
23442424-1.7.9
2525-=====
4545+1.7.11 (Apr 15, 2019)
4646+======
2647Fixes:
2748------
2828-* Fix a bug where `cJSON_GetObjectItemCaseSensitive` would pass a nullpointer to `strcmp` when called on an array (#315). Thanks @yuweol for reporting.
2929-* Fix error in `cJSON_Utils` where the case sensitivity was not respected (#317). Thanks @yuta-oxo for fixing.
3030-* Fix some warnings detected by the Visual Studio Static Analyzer (#307). Thanks @bnason-nf
4949+* Fix a bug where cJSON_Minify could overflow it's buffer, both reading and writing. This is a security issue, see [#338](https://github.com/DaveGamble/cJSON/issues/338). Big thanks @bigric3 for reporting.
5050+* Unset `true` and `false` macros before setting them if they exist. See [#339](https://github.com/DaveGamble/cJSON/issues/339), thanks @raiden00pl for reporting
31513232-1.7.8
5252+1.7.10 (Dec 21, 2018)
5353+======
5454+Fixes:
5555+------
5656+* Fix package config file for `libcjson`. Thanks @shiluotang for reporting [#321](https://github.com/DaveGamble/cJSON/issues/321)
5757+* Correctly split lists in `cJSON_Utils`'s merge sort. Thanks @andysCaplin for the fix [#322](https://github.com/DaveGamble/cJSON/issues/322)
5858+5959+1.7.9 (Dec 16, 2018)
3360=====
3461Fixes:
3562------
3636-* cJSON now works with the `__stdcall` calling convention on Windows, see #295, thanks @zhindes for contributing
6363+* Fix a bug where `cJSON_GetObjectItemCaseSensitive` would pass a nullpointer to `strcmp` when called on an array, see [#315](https://github.com/DaveGamble/cJSON/issues/315). Thanks @yuweol for reporting.
6464+* Fix error in `cJSON_Utils` where the case sensitivity was not respected, see [#317](https://github.com/DaveGamble/cJSON/pull/317). Thanks @yuta-oxo for fixing.
6565+* Fix some warnings detected by the Visual Studio Static Analyzer, see [#307](https://github.com/DaveGamble/cJSON/pull/307). Thanks @bnason-nf
37663838-1.7.7
6767+1.7.8 (Sep 22, 2018)
6868+======
6969+Fixes:
7070+------
7171+* cJSON now works with the `__stdcall` calling convention on Windows, see [#295](https://github.com/DaveGamble/cJSON/pull/295), thanks @zhindes for contributing
7272+7373+1.7.7 (May 22, 2018)
3974=====
4075Fixes:
4176------
4242-* Fix a memory leak when realloc fails (see #267), thanks @AlfieDeng for reporting
4343-* Fix a typo in the header file (see #266), thanks @zhaozhixu
7777+* Fix a memory leak when realloc fails, see [#267](https://github.com/DaveGamble/cJSON/issues/267), thanks @AlfieDeng for reporting
7878+* Fix a typo in the header file, see [#266](https://github.com/DaveGamble/cJSON/pull/266), thanks @zhaozhixu
44794545-1.7.6
8080+1.7.6 (Apr 13, 2018)
4681=====
4782Fixes:
4883------
4949-* Add `SONAME` to the ELF files built by the Makefile (see #252), thanks @YanhaoMo for reporting
5050-* Add include guards and `extern "C"` to `cJSON_Utils.h` (see #256), thanks @daschfg for reporting
8484+* Add `SONAME` to the ELF files built by the Makefile, see [#252](https://github.com/DaveGamble/cJSON/issues/252), thanks @YanhaoMo for reporting
8585+* Add include guards and `extern "C"` to `cJSON_Utils.h`, see [#256](https://github.com/DaveGamble/cJSON/issues/256), thanks @daschfg for reporting
51865287Other changes:
5353---------------
5488* Mark the Makefile as deprecated in the README.
55895656-1.7.5
9090+1.7.5 (Mar 23, 2018)
5791=====
5892Fixes:
5993------
6060-* Fix a bug in the JSON Patch implementation of `cJSON Utils` (see #251), thanks @bobkocisko.
9494+* Fix a bug in the JSON Patch implementation of `cJSON Utils`, see [#251](https://github.com/DaveGamble/cJSON/pull/251), thanks @bobkocisko.
61956262-1.7.4
9696+1.7.4 (Mar 3, 2018)
6397=====
6498Fixes:
6599------
6666-* Fix potential use after free if the `string` parameter to `cJSON_AddItemToObject` is an alias of the `string` property of the object that is added (#248). Thanks @hhallen for reporting.
100100+* Fix potential use after free if the `string` parameter to `cJSON_AddItemToObject` is an alias of the `string` property of the object that is added,see [#248](https://github.com/DaveGamble/cJSON/issues/248). Thanks @hhallen for reporting.
671016868-1.7.3
102102+1.7.3 (Feb 8, 2018)
69103=====
70104Fixes:
71105------
7272-* Fix potential double free, thanks @projectgus for reporting (see #241)
106106+* Fix potential double free, thanks @projectgus for reporting [#241](https://github.com/DaveGamble/cJSON/issues/241)
731077474-1.7.2
108108+1.7.2 (Feb 6, 2018)
75109=====
76110Fixes:
77111------
7878-* Fix the use of GNUInstallDirs variables and the pkgconfig file. Thanks @zeerd for reporting (see #240)
112112+* Fix the use of GNUInstallDirs variables and the pkgconfig file. Thanks @zeerd for reporting [#240](https://github.com/DaveGamble/cJSON/pull/240)
791138080-1.7.1
114114+1.7.1 (Jan 10, 2018)
81115=====
82116Fixes:
83117------
8484-* Fixed an Off-By-One error that could lead to an out of bounds write. Thanks @liuyunbin for reporting (see #230)
8585-* Fixed two errors with buffered printing. Thanks @liuyunbin for reporting (see #230)
118118+* Fixed an Off-By-One error that could lead to an out of bounds write. Thanks @liuyunbin for reporting [#230](https://github.com/DaveGamble/cJSON/issues/230)
119119+* Fixed two errors with buffered printing. Thanks @liuyunbin for reporting [#230](https://github.com/DaveGamble/cJSON/issues/230)
861208787-1.7.0
121121+1.7.0 (Dec 31, 2017)
88122=====
89123Features:
90124---------
9191-* Large rewrite of the documentation, see #215
125125+* Large rewrite of the documentation, see [#215](https://github.com/DaveGamble/cJSON/pull/215)
92126* Added the `cJSON_GetStringValue` function
93127* Added the `cJSON_CreateStringReference` function
94128* Added the `cJSON_CreateArrayReference` function
95129* Added the `cJSON_CreateObjectReference` function
9696-* The `cJSON_Add...ToObject` macros are now functions that return a pointer to the added item, see #226
130130+* The `cJSON_Add...ToObject` macros are now functions that return a pointer to the added item, see [#226](https://github.com/DaveGamble/cJSON/pull/226)
9713198132Fixes:
99133------
100100-* Fix a problem with `GNUInstallDirs` in the CMakeLists.txt, thanks @yangfl, see #210
101101-* Fix linking the tests when building as static library, see #213
102102-* New overrides for the CMake option `BUILD_SHARED_LIBS`, see #207
134134+* Fix a problem with `GNUInstallDirs` in the CMakeLists.txt, thanks @yangfl, see [#210](https://github.com/DaveGamble/cJSON/pull/210)
135135+* Fix linking the tests when building as static library, see [#213](https://github.com/DaveGamble/cJSON/issues/213)
136136+* New overrides for the CMake option `BUILD_SHARED_LIBS`, see [#207](https://github.com/DaveGamble/cJSON/issues/207)
103137104138Other Changes:
105139--------------
106106-* Readme: Explain how to include cJSON, see #211
107107-* Removed some trailing spaces in the code, thanks @yangfl, see#212
140140+* Readme: Explain how to include cJSON, see [#211](https://github.com/DaveGamble/cJSON/pull/211)
141141+* Removed some trailing spaces in the code, thanks @yangfl, see [#212](https://github.com/DaveGamble/cJSON/pull/212)
108142* Updated [Unity](https://github.com/ThrowTheSwitch/Unity) and [json-patch-tests](https://github.com/json-patch/json-patch-tests)
109143110110-1.6.0
144144+1.6.0 (Oct 9, 2017)
111145=====
112146Features:
113147---------
114114-* You can now build cJSON as both shared and static library at once with CMake using `-DBUILD_SHARED_AND_STATIC_LIBS=On`, see #178
115115-* UTF-8 byte order marks are now ignored, see #184
116116-* Locales can now be disabled with the option `-DENABLE_LOCALES=Off`, see #202, thanks @Casperinous
148148+* You can now build cJSON as both shared and static library at once with CMake using `-DBUILD_SHARED_AND_STATIC_LIBS=On`, see [#178](https://github.com/DaveGamble/cJSON/issues/178)
149149+* UTF-8 byte order marks are now ignored, see [#184](https://github.com/DaveGamble/cJSON/issues/184)
150150+* Locales can now be disabled with the option `-DENABLE_LOCALES=Off`, see [#202](https://github.com/DaveGamble/cJSON/issues/202), thanks @Casperinous
117151* Better support for MSVC and Visual Studio
118152119153Other Changes:
···122156* More number printing tests.
123157* Continuous integration testing with AppVeyor (semi automatic at this point), thanks @simon-p-r
124158125125-1.5.9
159159+1.5.9 (Sep 8, 2017)
126160=====
127127-* Set the global error pointer even if `return_parse_end` is passed to `cJSON_ParseWithOpts`. See #200, thanks @rmallins
161161+Fixes:
162162+------
163163+* Set the global error pointer even if `return_parse_end` is passed to `cJSON_ParseWithOpts`, see [#200](https://github.com/DaveGamble/cJSON/pull/200), thanks @rmallins
128164129129-1.5.8
165165+1.5.8 (Aug 21, 2017)
130166=====
131131-* Fix `make test` in the Makefile, thanks @YanhaoMo for reporting this (#195)
167167+Fixes:
168168+------
169169+* Fix `make test` in the Makefile, thanks @YanhaoMo for reporting this [#195](https://github.com/DaveGamble/cJSON/issues/195)
132170133133-1.5.7
171171+1.5.7 (Jul 13, 2017)
134172=====
135173Fixes:
136174------
137137-* Fix a bug where realloc failing would return a pointer to an invalid memory address. This is a security issue as it could potentially be used by an attacker to write to arbitrary memory addresses. (see #189), fixed in (954d61e5e7cb9dc6c480fc28ac1cdceca07dd5bd), big thanks @timothyjohncarney for reporting this issue
138138-* Fix a spelling mistake in the AFL fuzzer dictionary (#185), thanks @jwilk
175175+* Fix a bug where realloc failing would return a pointer to an invalid memory address. This is a security issue as it could potentially be used by an attacker to write to arbitrary memory addresses, see [#189](https://github.com/DaveGamble/cJSON/issues/189), fixed in [954d61e](https://github.com/DaveGamble/cJSON/commit/954d61e5e7cb9dc6c480fc28ac1cdceca07dd5bd), big thanks @timothyjohncarney for reporting this issue
176176+* Fix a spelling mistake in the AFL fuzzer dictionary, see [#185](https://github.com/DaveGamble/cJSON/pull/185), thanks @jwilk
139177140140-1.5.6
178178+1.5.6 (Jun 28, 2017)
141179=====
142180Fixes:
143181------
144144-* Make cJSON a lot more tolerant about passing NULL pointers to its functions, it should now fail safely instead of dereferencing the pointer. (#183) Thanks @msichal for reporting #182
182182+* Make cJSON a lot more tolerant about passing NULL pointers to its functions, it should now fail safely instead of dereferencing the pointer, see [#183](https://github.com/DaveGamble/cJSON/pull/183). Thanks @msichal for reporting [#182](https://github.com/DaveGamble/cJSON/issues/182)
145183146146-1.5.5
184184+1.5.5 (Jun 15, 2017)
147185=====
148186Fixes:
149187------
150150-* Fix pointers to nested arrays in cJSON_Utils (9abe75e072050f34732a7169740989a082b65134)
151151-* Fix an error with case sensitivity handling in cJSON_Utils (b9cc911831b0b3e1bb72f142389428e59f882b38)
152152-* Fix cJSON_Compare for arrays that are prefixes of the other and objects that are a subset of the other (03ba72faec115160d1f3aea5582d9b6af5d3e473) See #180, thanks @zhengqb for reporting
188188+* Fix pointers to nested arrays in cJSON_Utils, see [9abe](https://github.com/DaveGamble/cJSON/commit/9abe75e072050f34732a7169740989a082b65134)
189189+* Fix an error with case sensitivity handling in cJSON_Utils, see [b9cc911](https://github.com/DaveGamble/cJSON/commit/b9cc911831b0b3e1bb72f142389428e59f882b38)
190190+* Fix cJSON_Compare for arrays that are prefixes of the other and objects that are a subset of the other, see [03ba72f](https://github.com/DaveGamble/cJSON/commit/03ba72faec115160d1f3aea5582d9b6af5d3e473) and [#180](https://github.com/DaveGamble/cJSON/issues/180), thanks @zhengqb for reporting
153191154154-1.5.4
155155-=====
192192+1.5.4 (Jun 5, 2017)
193193+======
156194Fixes:
157195------
158158-* Fix build with GCC 7.1.1 and optimization level `-O2` (bfbd8fe0d85f1dd21e508748fc10fc4c27cc51be)
196196+* Fix build with GCC 7.1.1 and optimization level `-O2`, see [bfbd8fe](https://github.com/DaveGamble/cJSON/commit/bfbd8fe0d85f1dd21e508748fc10fc4c27cc51be)
159197160198Other Changes:
161199--------------
162200* Update [Unity](https://github.com/ThrowTheSwitch/Unity) to 3b69beaa58efc41bbbef70a32a46893cae02719d
163201164164-1.5.3
202202+1.5.3 (May 23, 2017)
165203=====
166204Fixes:
167205------
168168-* Fix `cJSON_ReplaceItemInObject` not keeping the name of an item (#174)
206206+* Fix `cJSON_ReplaceItemInObject` not keeping the name of an item, see [#174](https://github.com/DaveGamble/cJSON/issues/174)
169207170170-1.5.2
208208+1.5.2 (May 10, 2017)
171209=====
172210Fixes:
173211------
174174-* Fix a reading buffer overflow in `parse_string` (a167d9e381e5c84bc03de4e261757b031c0c690d)
175175-* Fix compiling with -Wcomma (186cce3ece6ce6dfcb58ac8b2a63f7846c3493ad)
176176-* Remove leftover attribute from tests (b537ca70a35680db66f1f5b8b437f7114daa699a)
212212+* Fix a reading buffer overflow in `parse_string`, see [a167d9e](https://github.com/DaveGamble/cJSON/commit/a167d9e381e5c84bc03de4e261757b031c0c690d)
213213+* Fix compiling with -Wcomma, see [186cce3](https://github.com/DaveGamble/cJSON/commit/186cce3ece6ce6dfcb58ac8b2a63f7846c3493ad)
214214+* Remove leftover attribute from tests, see [b537ca7](https://github.com/DaveGamble/cJSON/commit/b537ca70a35680db66f1f5b8b437f7114daa699a)
177215178178-1.5.1
216216+1.5.1 (May 6, 2017)
179217=====
180218Fixes:
181219------
182182-* Add gcc version guard to the Makefile (#164), thanks @juvasquezg
183183-* Fix incorrect free in `cJSON_Utils` if custom memory allocator is used (#166), thanks @prefetchnta
220220+* Add gcc version guard to the Makefile, see [#164](https://github.com/DaveGamble/cJSON/pull/164), thanks @juvasquezg
221221+* Fix incorrect free in `cJSON_Utils` if custom memory allocator is used, see [#166](https://github.com/DaveGamble/cJSON/pull/166), thanks @prefetchnta
184222185185-1.5.0
223223+1.5.0 (May 2, 2017)
186224=====
187225Features:
188188----------
189189-* cJSON finally prints numbers without losing precision (#153) thanks @DeboraG
190190-* `cJSON_Compare` recursively checks if two cJSON items contain the same values (#148)
191191-* Provide case sensitive versions of every function where it matters (#158, #159)
226226+* cJSON finally prints numbers without losing precision, see [#153](https://github.com/DaveGamble/cJSON/pull/153), thanks @DeboraG
227227+* `cJSON_Compare` recursively checks if two cJSON items contain the same values, see [#148](https://github.com/DaveGamble/cJSON/pull/148)
228228+* Provide case sensitive versions of every function where it matters, see [#158](https://github.com/DaveGamble/cJSON/pull/158) and [#159](https://github.com/DaveGamble/cJSON/pull/159)
192229* Added `cJSON_ReplaceItemViaPointer` and `cJSON_DetachItemViaPointer`
193193-* Added `cJSON_free` and `cJSON_malloc` that expose the internal configured memory allocators. (02a05eea4e6ba41811f130b322660bea8918e1a0)
230230+* Added `cJSON_free` and `cJSON_malloc` that expose the internal configured memory allocators. see [02a05ee](https://github.com/DaveGamble/cJSON/commit/02a05eea4e6ba41811f130b322660bea8918e1a0)
194231195232196233Enhancements:
···204241205242Fixes:
206243------
207207-* Fix some warnings with the Microsoft compiler (#139) thanks @PawelWMS
244244+* Fix some warnings with the Microsoft compiler, see [#139](https://github.com/DaveGamble/cJSON/pull/139), thanks @PawelWMS
208245* Fix several bugs in cJSON_Utils, mostly found with [json-patch-tests](https://github.com/json-patch/json-patch-tests)
209246* Prevent a stack overflow by specifying a maximum nesting depth `CJSON_NESTING_LIMIT`
210247···212249--------------
213250* Move generated files in the `library_config` subdirectory.
214251215215-1.4.7
252252+1.4.7 (Apr 19, 2017)
216253=====
217254Fixes:
218255------
219219-* Fix `cJSONUtils_ApplyPatches`, it was completely broken and apparently nobody noticed (or at least reported it) (075a06f40bdc4f836c7dd7cad690d253a57cfc50)
220220-* Fix inconsistent prototype for `cJSON_GetObjectItemCaseSensitive` (51d3df6c9f7b56b860c8fb24abe7bab255cd4fa9) thanks @PawelWMS
256256+* Fix `cJSONUtils_ApplyPatches`, it was completely broken and apparently nobody noticed (or at least reported it), see [075a06f](https://github.com/DaveGamble/cJSON/commit/075a06f40bdc4f836c7dd7cad690d253a57cfc50)
257257+* Fix inconsistent prototype for `cJSON_GetObjectItemCaseSensitive`, see [51d3df6](https://github.com/DaveGamble/cJSON/commit/51d3df6c9f7b56b860c8fb24abe7bab255cd4fa9), thanks @PawelWMS
221258222222-1.4.6
259259+1.4.6 (Apr 9, 2017)
223260=====
224261Fixes:
225262------
226263* Several corrections in the README
227264* Making clear that `valueint` should not be written to
228228-* Fix overflow detection in `ensure` (2683d4d9873df87c4bdccc523903ddd78d1ad250)
229229-* Fix a potential null pointer dereference in cJSON_Utils (795c3acabed25c9672006b2c0f40be8845064827)
230230-* Replace incorrect `sizeof('\0')` with `sizeof("")` (84237ff48e69825c94261c624eb0376d0c328139)
231231-* Add caveats section to the README (50b3c30dfa89830f8f477ce33713500740ac3b79)
232232-* Make cJSON locale independent (#146) Thanks @peterh for reporting
233233-* Fix compiling without CMake with MSVC (#147) Thanks @dertuxmalwieder for reporting
265265+* Fix overflow detection in `ensure`, see [2683d4d](https://github.com/DaveGamble/cJSON/commit/2683d4d9873df87c4bdccc523903ddd78d1ad250)
266266+* Fix a potential null pointer dereference in cJSON_Utils, see [795c3ac](https://github.com/DaveGamble/cJSON/commit/795c3acabed25c9672006b2c0f40be8845064827)
267267+* Replace incorrect `sizeof('\0')` with `sizeof("")`, see [84237ff](https://github.com/DaveGamble/cJSON/commit/84237ff48e69825c94261c624eb0376d0c328139)
268268+* Add caveats section to the README, see [50b3c30](https://github.com/DaveGamble/cJSON/commit/50b3c30dfa89830f8f477ce33713500740ac3b79)
269269+* Make cJSON locale independent, see [#146](https://github.com/DaveGamble/cJSON/pull/146), Thanks @peterh for reporting
270270+* Fix compiling without CMake with MSVC, see [#147](https://github.com/DaveGamble/cJSON/pull/147), Thanks @dertuxmalwieder for reporting
234271235235-1.4.5
272272+1.4.5 (Mar 28, 2017)
236273=====
237274Fixes:
238275------
239239-* Fix bug in `cJSON_SetNumberHelper`, thanks @mmkeeper (#138 ef34500693e8c4a2849d41a4bd66fd19c9ec46c2)
276276+* Fix bug in `cJSON_SetNumberHelper`, thanks @mmkeeper, see [#138](https://github.com/DaveGamble/cJSON/issues/138) and [ef34500](https://github.com/DaveGamble/cJSON/commit/ef34500693e8c4a2849d41a4bd66fd19c9ec46c2)
240277* Workaround for internal compiler error in GCC 5.4.0 and 6.3.1 on x86 (2f65e80a3471d053fdc3f8aed23d01dd1782a5cb [GCC bugreport](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80097))
241278242242-1.4.4
279279+1.4.4 (Mar 24, 2017)
243280=====
244281Fixes:
245245---------
246246-* Fix a theoretical integer overflow, (not sure if it is possible on actual hardware) e58f7ec027d00b7cdcbf63e518c1b5268b29b3da
247247-* Fix an off by one error (cc84a446be20cc283bafdc4d94c050ba1111ac02), thanks @gatzka
248248-* Double check the offset of the print buffer in `ensure` (1934059554b9a0971e00f79e96900f422cfdd114)
282282+------
283283+* Fix a theoretical integer overflow, (not sure if it is possible on actual hardware), see [e58f7ec](https://github.com/DaveGamble/cJSON/commit/e58f7ec027d00b7cdcbf63e518c1b5268b29b3da)
284284+* Fix an off by one error, see [cc84a44](https://github.com/DaveGamble/cJSON/commit/cc84a446be20cc283bafdc4d94c050ba1111ac02), thanks @gatzka
285285+* Double check the offset of the print buffer in `ensure`, see [1934059](https://github.com/DaveGamble/cJSON/commit/1934059554b9a0971e00f79e96900f422cfdd114)
249286250287Improvements:
251251--------------
252252-* Add a note in the header about required buffer size when using `cJSON_PrintPreallocated` (4bfb88009342fb568295a7f6dc4b7fee74fbf022)
288288+* Add a note in the header about required buffer size when using `cJSON_PrintPreallocated`, see [4bfb8800](https://github.com/DaveGamble/cJSON/commit/4bfb88009342fb568295a7f6dc4b7fee74fbf022)
253289254254-1.4.3
290290+1.4.3 (Mar 19, 2017)
255291=====
256292Fixes:
257293------
258258-* Fix compilation of the tests on 32 bit PowerPC and potentially other systems (4ec6e76ea2eec16f54b58e8c95b4c734e59481e4)
259259-* Fix compilation with old GCC compilers (4.3+ were tested) (227d3398d6b967879761ebe02c1b63dbd6ea6e0d, 466eb8e3f8a65080f2b3ca4a79ab7b72bd539dba), see also #126
294294+* Fix compilation of the tests on 32 bit PowerPC and potentially other systems, see [4ec6e76](https://github.com/DaveGamble/cJSON/commit/4ec6e76ea2eec16f54b58e8c95b4c734e59481e4)
295295+* Fix compilation with old GCC compilers (4.3+ were tested), see [227d33](https://github.com/DaveGamble/cJSON/commit/227d3398d6b967879761ebe02c1b63dbd6ea6e0d), [466eb8e](https://github.com/DaveGamble/cJSON/commit/466eb8e3f8a65080f2b3ca4a79ab7b72bd539dba), see also [#126](https://github.com/DaveGamble/cJSON/issues/126)
260296261261-1.4.2
297297+1.4.2 (Mar 16, 2017)
262298=====
263299Fixes:
264300------
265265-* Fix minimum required cmake version (30e1e7af7c63db9b55f5a3cda977a6c032f0b132)
266266-* Fix detection of supported compiler flags (76e5296d0d05ceb3018a9901639e0e171b44a557)
267267-* Run `cJSON_test` and `cJSON_test_utils` along with unity tests (c597601cf151a757dcf800548f18034d4ddfe2cb)
301301+* Fix minimum required cmake version, see [30e1e7a](https://github.com/DaveGamble/cJSON/commit/30e1e7af7c63db9b55f5a3cda977a6c032f0b132)
302302+* Fix detection of supported compiler flags, see [76e5296](https://github.com/DaveGamble/cJSON/commit/76e5296d0d05ceb3018a9901639e0e171b44a557)
303303+* Run `cJSON_test` and `cJSON_test_utils` along with unity tests, see [c597601](https://github.com/DaveGamble/cJSON/commit/c597601cf151a757dcf800548f18034d4ddfe2cb)
268304269269-1.4.1
305305+1.4.1 (Mar 16, 2017)
270306=====
271271-Fix: Make `print_number` abort with a failure in out of memory situations (cf1842dc6f64c49451a022308b4415e4d468be0a)
307307+Fixes:
308308+------
309309+* Make `print_number` abort with a failure in out of memory situations, see [cf1842](https://github.com/DaveGamble/cJSON/commit/cf1842dc6f64c49451a022308b4415e4d468be0a)
272310273273-1.4.0
311311+1.4.0 (Mar 4, 2017)
274312=====
275313Features
276314--------
277277-* Functions to check the type of an item (#120)
278278-* Use dllexport on windows and fvisibility on Unix systems for public functions (#116), thanks @mjerris
279279-* Remove trailing zeroes from printed numbers (#123)
280280-* Expose the internal boolean type `cJSON_bool` in the header (2d3520e0b9d0eb870e8886e8a21c571eeddbb310)
315315+* Functions to check the type of an item, see [#120](https://github.com/DaveGamble/cJSON/pull/120)
316316+* Use dllexport on windows and fvisibility on Unix systems for public functions, see [#116](https://github.com/DaveGamble/cJSON/pull/116), thanks @mjerris
317317+* Remove trailing zeroes from printed numbers, see [#123](https://github.com/DaveGamble/cJSON/pull/123)
318318+* Expose the internal boolean type `cJSON_bool` in the header, see [2d3520e](https://github.com/DaveGamble/cJSON/commit/2d3520e0b9d0eb870e8886e8a21c571eeddbb310)
281319282320Fixes
283283------
284284-* Fix handling of NULL pointers in `cJSON_ArrayForEach` (b47d0e34caaef298edfb7bd09a72cfff21d231ff)
285285-* Make it compile with GCC 7 (fix -Wimplicit-fallthrough warning) (9d07917feb1b613544a7513d19233d4c851ad7ad)
321321+* Fix handling of NULL pointers in `cJSON_ArrayForEach`, see [b47d0e3](https://github.com/DaveGamble/cJSON/commit/b47d0e34caaef298edfb7bd09a72cfff21d231ff)
322322+* Make it compile with GCC 7 (fix -Wimplicit-fallthrough warning), see [9d07917](https://github.com/DaveGamble/cJSON/commit/9d07917feb1b613544a7513d19233d4c851ad7ad)
286323287324Other Improvements
288288-------------------
289289-* internally use realloc if available (#110)
290290-* builtin support for fuzzing with [afl](http://lcamtuf.coredump.cx/afl/) (#111)
291291-* unit tests for the print functions (#112)
292292-* Always use buffered printing (#113)
293293-* simplify the print functions (#114)
294294-* Add the compiler flags `-Wdouble-conversion`, `-Wparentheses` and `-Wcomma` (#122)
325325+* internally use realloc if available ([#110](https://github.com/DaveGamble/cJSON/pull/110))
326326+* builtin support for fuzzing with [afl](http://lcamtuf.coredump.cx/afl/) ([#111](https://github.com/DaveGamble/cJSON/pull/111))
327327+* unit tests for the print functions ([#112](https://github.com/DaveGamble/cJSON/pull/112))
328328+* Always use buffered printing ([#113](https://github.com/DaveGamble/cJSON/pull/113))
329329+* simplify the print functions ([#114](https://github.com/DaveGamble/cJSON/pull/114))
330330+* Add the compiler flags `-Wdouble-conversion`, `-Wparentheses` and `-Wcomma` ([#122](https://github.com/DaveGamble/cJSON/pull/122))
295331296296-1.3.2
332332+1.3.2 (Mar 1, 2017)
297333=====
298298-Fix:
299299-----
300300-- Don't build the unity library if testing is disabled ( #121 ). Thanks @ffontaine
334334+Fixes:
335335+------
336336+* Don't build the unity library if testing is disabled, see [#121](https://github.com/DaveGamble/cJSON/pull/121). Thanks @ffontaine
301337302302-1.3.1
338338+1.3.1 (Feb 27, 2017)
303339=====
304304-Bugfix release that fixes an out of bounds read #118. This shouldn't have any security implications.
340340+Fixes:
341341+------
342342+* Bugfix release that fixes an out of bounds read, see [#118](https://github.com/DaveGamble/cJSON/pull/118). This shouldn't have any security implications.
305343306306-1.3.0
344344+1.3.0 (Feb 17, 2017)
307345=====
308346This release includes a lot of rework in the parser and includes the Cunity unit testing framework, as well as some fixes. I increased the minor version number because there were quite a lot of internal changes.
309347310348Features:
311311----------
312312-- New type for cJSON structs: `cJSON_Invalid` (#108)
349349+* New type for cJSON structs: `cJSON_Invalid`, see [#108](https://github.com/DaveGamble/cJSON/pull/108)
313350314351Fixes:
315352------
316316-- runtime checks for a lot of potential integer overflows
317317-- fix incorrect return in cJSON_PrintBuffered (cf9d57d56cac21fc59465b8d26cf29bf6d2a87b3)
318318-- fix several potential issues found by [Coverity](https://scan.coverity.com/projects/cjson)
319319-- fix potentially undefined behavior when assigning big numbers to `valueint` (41e2837df1b1091643aff073f2313f6ff3cc10f4)
320320- - Numbers exceeding `INT_MAX` or lower than `INT_MIN` will be explicitly assigned to `valueint` as `INT_MAX` and `INT_MIN` respectively (saturation on overflow).
321321- - fix the `cJSON_SetNumberValue` macro (87f77274de6b3af00fb9b9a7f3b900ef382296c2), this slightly changes the behavior, see commit message
353353+* runtime checks for a lot of potential integer overflows
354354+* fix incorrect return in cJSON_PrintBuffered [cf9d57d](https://github.com/DaveGamble/cJSON/commit/cf9d57d56cac21fc59465b8d26cf29bf6d2a87b3)
355355+* fix several potential issues found by [Coverity](https://scan.coverity.com/projects/cjson)
356356+* fix potentially undefined behavior when assigning big numbers to `valueint` ([41e2837](https://github.com/DaveGamble/cJSON/commit/41e2837df1b1091643aff073f2313f6ff3cc10f4))
357357+ * Numbers exceeding `INT_MAX` or lower than `INT_MIN` will be explicitly assigned to `valueint` as `INT_MAX` and `INT_MIN` respectively (saturation on overflow).
358358+ * fix the `cJSON_SetNumberValue` macro ([87f7727](https://github.com/DaveGamble/cJSON/commit/87f77274de6b3af00fb9b9a7f3b900ef382296c2)), this slightly changes the behavior, see commit message
322359323360Introduce unit tests
324361--------------------
325362326326-Started writing unit tests with the [Cunity](https://github.com/ThrowTheSwitch/Unity) testing framework. Currently this covers the parser functions.
363363+* Started writing unit tests with the [Cunity](https://github.com/ThrowTheSwitch/Unity) testing framework. Currently this covers the parser functions.
327364328365Also:
329329-- Support for running the tests with [Valgrind](http://valgrind.org)
330330-- Support for compiling the tests with [AddressSanitizer](https://github.com/google/sanitizers) and [UndefinedBehaviorSanitizer](https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html).
331331-- `travis.yml` file for running unit tests on travis. (not enabled for the repository yet though #102)
366366+* Support for running the tests with [Valgrind](http://valgrind.org)
367367+* Support for compiling the tests with [AddressSanitizer](https://github.com/google/sanitizers) and [UndefinedBehaviorSanitizer](https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html).
368368+* `travis.yml` file for running unit tests on travis. (not enabled for the repository yet though [#102](https://github.com/DaveGamble/cJSON/issues/102)
332369333370Simplifications
334371---------------
335372336373After having unit tests for the parser function in place, I started refactoring the parser functions (as well as others) and making them easier to read and maintain.
337337-- Use `strtod` from the standard library for parsing numbers (074766997246481dfc72bfa78f07898a2716473f)
338338-- Use goto-fail in several parser functions (#100)
339339-- Rewrite/restructure all of the parsing functions to be easier to understand and have less code paths doing the same as another. (#109)
340340-- Simplify the buffer allocation strategy to always doubling the needed amount (9f6fa94c91a87b71e4c6868dbf2ce431a48517b0)
341341-- Combined `cJSON_AddItemToObject` and `cJSON_AddItemToObjectCS` to one function (cf862d0fed7f9407e4b046d78d3d8050d2080d12)
374374+* Use `strtod` from the standard library for parsing numbers ([0747669](https://github.com/DaveGamble/cJSON/commit/074766997246481dfc72bfa78f07898a2716473f))
375375+* Use goto-fail in several parser functions ([#100](https://github.com/DaveGamble/cJSON/pull/100))
376376+* Rewrite/restructure all of the parsing functions to be easier to understand and have less code paths doing the same as another. ([#109](https://github.com/DaveGamble/cJSON/pull/109))
377377+* Simplify the buffer allocation strategy to always doubling the needed amount ([9f6fa94](https://github.com/DaveGamble/cJSON/commit/9f6fa94c91a87b71e4c6868dbf2ce431a48517b0))
378378+* Combined `cJSON_AddItemToObject` and `cJSON_AddItemToObjectCS` to one function ([cf862d](https://github.com/DaveGamble/cJSON/commit/cf862d0fed7f9407e4b046d78d3d8050d2080d12))
342379343380Other changes
344381-------------
345345-- Prevent the usage of incompatible C and header versions via preprocessor directive (123bb1af7bfae41d805337fef4b41045ef6c7d25)
346346-- Let CMake automatically detect compiler flags
347347-- Add new compiler flags (`-Wundef`, `-Wswitch-default`, `-Wconversion`, `-fstack-protector-strong`) (#98)
348348-- Change internal sizes from `int` to `size_t` (ecd5678527a6bc422da694e5be9e9979878fe6a0)
349349-- Change internal strings from `char*` to `unsigned char*` (28b9ba4334e0f7309e867e874a31f395c0ac2474)
350350-- Add `const` in more places
382382+* Prevent the usage of incompatible C and header versions via preprocessor directive ([123bb1](https://github.com/DaveGamble/cJSON/commit/123bb1af7bfae41d805337fef4b41045ef6c7d25))
383383+* Let CMake automatically detect compiler flags
384384+* Add new compiler flags (`-Wundef`, `-Wswitch-default`, `-Wconversion`, `-fstack-protector-strong`) ([#98](https://github.com/DaveGamble/cJSON/pull/98))
385385+* Change internal sizes from `int` to `size_t` ([ecd5678](https://github.com/DaveGamble/cJSON/commit/ecd5678527a6bc422da694e5be9e9979878fe6a0))
386386+* Change internal strings from `char*` to `unsigned char*` ([28b9ba4](https://github.com/DaveGamble/cJSON/commit/28b9ba4334e0f7309e867e874a31f395c0ac2474))
387387+* Add `const` in more places
351388352352-1.2.1
389389+1.2.1 (Jan 31, 2017)
353390=====
354391Fixes:
355392------
356356-- Fixes a potential null pointer dereference in cJSON_Utils, discovered using clang's static analyzer by @bnason-nf (#96)
393393+* Fixes a potential null pointer dereference in cJSON_Utils, discovered using clang's static analyzer by @bnason-nf, see [#96](https://github.com/DaveGamble/cJSON/issues/96)
357394358358-1.2.0
395395+1.2.0 (Jan 9, 2017)
359396=====
360397Features:
361398---------
362362-- Add a new type of cJSON item for raw JSON and support printing it. Thanks @loigu (#65, #90)
399399+* Add a new type of cJSON item for raw JSON and support printing it. Thanks @loigu, see [#65](https://github.com/DaveGamble/cJSON/pull/65), [#90](https://github.com/DaveGamble/cJSON/pull/90)
363400364401Fixes:
365402------
366366-- Compiler warning if const is casted away, Thanks @gatzka (#83)
367367-- Fix compile error with strict-overflow on PowerPC, (#85)
368368-- Fix typo in the README, thanks @MicroJoe (#88)
369369-- Add compile flag for compatibility with C++ compilers
403403+* Compiler warning if const is casted away, Thanks @gatzka, see [#83](https://github.com/DaveGamble/cJSON/pull/83)
404404+* Fix compile error with strict-overflow on PowerPC, see [#85](https://github.com/DaveGamble/cJSON/issues/85)
405405+* Fix typo in the README, thanks @MicroJoe, see [#88](https://github.com/DaveGamble/cJSON/pull/88)
406406+* Add compile flag for compatibility with C++ compilers
370407371371-1.1.0
408408+1.1.0 (Dec 6, 2016)
372409=====
373373-- Add a function `cJSON_PrintPreallocated` to print to a preallocated buffer, thanks @ChisholmKyle (#72)
374374-- More compiler warnings when using Clang or GCC, thanks @gatzka (#75, #78)
375375-- fixed a memory leak in `cJSON_Duplicate`, thanks @alperakcan (#81)
376376-- fix the `ENABLE_CUSTOM_COMPILER_FLAGS` cmake option
410410+* Add a function `cJSON_PrintPreallocated` to print to a preallocated buffer, thanks @ChisholmKyle, see [#72](https://github.com/DaveGamble/cJSON/pull/72)
411411+* More compiler warnings when using Clang or GCC, thanks @gatzka, see [#75](https://github.com/DaveGamble/cJSON/pull/75), [#78](https://github.com/DaveGamble/cJSON/pull/78)
412412+* fixed a memory leak in `cJSON_Duplicate`, thanks @alperakcan, see [#81](https://github.com/DaveGamble/cJSON/pull/81)
413413+* fix the `ENABLE_CUSTOM_COMPILER_FLAGS` cmake option
377414378378-1.0.2
415415+1.0.2 (Nov 25, 2016)
379416=====
380380-Rename internal boolean type, see #71.
417417+* Rename internal boolean type, see [#71](https://github.com/DaveGamble/cJSON/issues/71).
381418382382-1.0.1
419419+1.0.1 (Nov 20, 2016)
383420=====
384421Small bugfix release.
385385-- Fixes a bug with the use of the cJSON structs type in cJSON_Utils, see d47339e2740360e6e0994527d5e4752007480f3a
386386-- improve code readability
387387-- initialize all variables
422422+* Fixes a bug with the use of the cJSON structs type in cJSON_Utils, see [d47339e](https://github.com/DaveGamble/cJSON/commit/d47339e2740360e6e0994527d5e4752007480f3a)
423423+* improve code readability
424424+* initialize all variables
388425389389-1.0.0
426426+1.0.0 (Nov 17, 2016)
390427=====
391428This is the first official versioned release of cJSON. It provides an API version for the shared library and improved Makefile and CMake build files.
···4343#include <stdlib.h>
4444#include <limits.h>
4545#include <ctype.h>
4646+#include <float.h>
46474748#ifdef ENABLE_LOCALES
4849#include <locale.h>
···6869#endif
6970#define false ((cJSON_bool)0)
70717272+/* define isnan and isinf for ANSI C, if in C99 or above, isnan and isinf has been defined in math.h */
7373+#ifndef isinf
7474+#define isinf(d) (isnan((d - d)) && !isnan(d))
7575+#endif
7676+#ifndef isnan
7777+#define isnan(d) (d != d)
7878+#endif
7979+8080+#ifndef NAN
8181+#ifdef _WIN32
8282+#define NAN sqrt(-1.0)
8383+#else
8484+#define NAN 0.0/0.0
8585+#endif
8686+#endif
8787+7188typedef struct {
7289 const unsigned char *json;
7390 size_t position;
···7996 return (const char*) (global_error.json + global_error.position);
8097}
81988282-CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item) {
8383- if (!cJSON_IsString(item)) {
9999+CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item)
100100+{
101101+ if (!cJSON_IsString(item))
102102+ {
84103 return NULL;
85104 }
8610587106 return item->valuestring;
88107}
89108109109+CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item)
110110+{
111111+ if (!cJSON_IsNumber(item))
112112+ {
113113+ return (double) NAN;
114114+ }
115115+116116+ return item->valuedouble;
117117+}
118118+90119/* This is a safeguard to prevent copy-pasters from using incompatible C and header files */
9191-#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 12)
120120+#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 15)
92121 #error cJSON.h and cJSON.c have different versions. Make sure that both have the same.
93122#endif
94123···368397 return object->valuedouble = number;
369398}
370399400400+CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring)
401401+{
402402+ char *copy = NULL;
403403+ /* if object's type is not cJSON_String or is cJSON_IsReference, it should not set valuestring */
404404+ if (!(object->type & cJSON_String) || (object->type & cJSON_IsReference))
405405+ {
406406+ return NULL;
407407+ }
408408+ if (strlen(valuestring) <= strlen(object->valuestring))
409409+ {
410410+ strcpy(object->valuestring, valuestring);
411411+ return object->valuestring;
412412+ }
413413+ copy = (char*) cJSON_strdup((const unsigned char*)valuestring, &global_hooks);
414414+ if (copy == NULL)
415415+ {
416416+ return NULL;
417417+ }
418418+ if (object->valuestring != NULL)
419419+ {
420420+ cJSON_free(object->valuestring);
421421+ }
422422+ object->valuestring = copy;
423423+424424+ return copy;
425425+}
426426+371427typedef struct
372428{
373429 unsigned char *buffer;
···455511456512 return NULL;
457513 }
458458- if (newbuffer)
459459- {
460460- memcpy(newbuffer, p->buffer, p->offset + 1);
461461- }
514514+515515+ memcpy(newbuffer, p->buffer, p->offset + 1);
462516 p->hooks.deallocate(p->buffer);
463517 }
464518 p->length = newsize;
···480534 buffer->offset += strlen((const char*)buffer_pointer);
481535}
482536537537+/* securely comparison of floating-point variables */
538538+static cJSON_bool compare_double(double a, double b)
539539+{
540540+ double maxVal = fabs(a) > fabs(b) ? fabs(a) : fabs(b);
541541+ return (fabs(a - b) <= maxVal * DBL_EPSILON);
542542+}
543543+483544/* Render the number nicely from the given item into a string. */
484545static cJSON_bool print_number(const cJSON * const item, printbuffer * const output_buffer)
485546{
···497558 }
498559499560 /* This checks for NaN and Infinity */
500500- if ((d * 0) != 0)
561561+ if (isnan(d) || isinf(d))
501562 {
502563 length = sprintf((char*)number_buffer, "null");
503564 }
···507568 length = sprintf((char*)number_buffer, "%1.15g", d);
508569509570 /* Check whether the original double can be recovered */
510510- if ((sscanf((char*)number_buffer, "%lg", &test) != 1) || ((double)test != d))
571571+ if ((sscanf((char*)number_buffer, "%lg", &test) != 1) || !compare_double((double)test, d))
511572 {
512573 /* If not, print with 17 decimal places of precision */
513574 length = sprintf((char*)number_buffer, "%1.17g", d);
···9771038 return NULL;
9781039 }
979104010411041+ if (cannot_access_at_index(buffer, 0))
10421042+ {
10431043+ return buffer;
10441044+ }
10451045+9801046 while (can_access_at_index(buffer, 0) && (buffer_at_offset(buffer)[0] <= 32))
9811047 {
9821048 buffer->offset++;
···10061072 return buffer;
10071073}
1008107410091009-/* Parse an object - create a new root, and populate. */
10101075CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated)
10111076{
10771077+ size_t buffer_length;
10781078+10791079+ if (NULL == value)
10801080+ {
10811081+ return NULL;
10821082+ }
10831083+10841084+ /* Adding null character size due to require_null_terminated. */
10851085+ buffer_length = strlen(value) + sizeof("");
10861086+10871087+ return cJSON_ParseWithLengthOpts(value, buffer_length, return_parse_end, require_null_terminated);
10881088+}
10891089+10901090+/* Parse an object - create a new root, and populate. */
10911091+CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated)
10921092+{
10121093 parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } };
10131094 cJSON *item = NULL;
10141095···10161097 global_error.json = NULL;
10171098 global_error.position = 0;
1018109910191019- if (value == NULL)
11001100+ if (value == NULL || 0 == buffer_length)
10201101 {
10211102 goto fail;
10221103 }
1023110410241105 buffer.content = (const unsigned char*)value;
10251025- buffer.length = strlen((const char*)value) + sizeof("");
11061106+ buffer.length = buffer_length;
10261107 buffer.offset = 0;
10271108 buffer.hooks = global_hooks;
10281109···10921173 return cJSON_ParseWithOpts(value, 0, 0);
10931174}
1094117510951095-#define cjson_min(a, b) ((a < b) ? a : b)
11761176+CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length)
11771177+{
11781178+ return cJSON_ParseWithLengthOpts(value, buffer_length, 0, 0);
11791179+}
11801180+11811181+#define cjson_min(a, b) (((a) < (b)) ? (a) : (b))
1096118210971183static unsigned char *print(const cJSON * const item, cJSON_bool format, const internal_hooks * const hooks)
10981184{
···11991285 return (char*)p.buffer;
12001286}
1201128712021202-CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buf, const int len, const cJSON_bool fmt)
12881288+CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format)
12031289{
12041290 printbuffer p = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } };
1205129112061206- if ((len < 0) || (buf == NULL))
12921292+ if ((length < 0) || (buffer == NULL))
12071293 {
12081294 return false;
12091295 }
1210129612111211- p.buffer = (unsigned char*)buf;
12121212- p.length = (size_t)len;
12971297+ p.buffer = (unsigned char*)buffer;
12981298+ p.length = (size_t)length;
12131299 p.offset = 0;
12141300 p.noalloc = true;
12151215- p.format = fmt;
13011301+ p.format = format;
12161302 p.hooks = global_hooks;
1217130312181304 return print_value(item, &p);
···14251511success:
14261512 input_buffer->depth--;
1427151315141514+ if (head != NULL) {
15151515+ head->prev = current_item;
15161516+ }
15171517+14281518 item->type = cJSON_Array;
14291519 item->child = head;
14301520···15971687success:
15981688 input_buffer->depth--;
1599168916901690+ if (head != NULL) {
16911691+ head->prev = current_item;
16921692+ }
16931693+16001694 item->type = cJSON_Object;
16011695 item->child = head;
16021696···18591953{
18601954 cJSON *child = NULL;
1861195518621862- if ((item == NULL) || (array == NULL))
19561956+ if ((item == NULL) || (array == NULL) || (array == item))
18631957 {
18641958 return false;
18651959 }
1866196018671961 child = array->child;
18681868-19621962+ /*
19631963+ * To find the last item in array quickly, we use prev in array
19641964+ */
18691965 if (child == NULL)
18701966 {
18711967 /* list is empty, start new one */
18721968 array->child = item;
19691969+ item->prev = item;
19701970+ item->next = NULL;
18731971 }
18741972 else
18751973 {
18761974 /* append to the end */
18771877- while (child->next)
19751975+ if (child->prev)
18781976 {
18791879- child = child->next;
19771977+ suffix_object(child->prev, item);
19781978+ array->child->prev = item;
18801979 }
18811881- suffix_object(child, item);
18821980 }
1883198118841982 return true;
18851983}
1886198418871985/* Add item to array/object. */
18881888-CJSON_PUBLIC(void) cJSON_AddItemToArray(cJSON *array, cJSON *item)
19861986+CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item)
18891987{
18901890- add_item_to_array(array, item);
19881988+ return add_item_to_array(array, item);
18911989}
1892199018931991#if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5))))
···19112009 char *new_key = NULL;
19122010 int new_type = cJSON_Invalid;
1913201119141914- if ((object == NULL) || (string == NULL) || (item == NULL))
20122012+ if ((object == NULL) || (string == NULL) || (item == NULL) || (object == item))
19152013 {
19162014 return false;
19172015 }
···19432041 return add_item_to_array(object, item);
19442042}
1945204319461946-CJSON_PUBLIC(void) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item)
20442044+CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item)
19472045{
19481948- add_item_to_object(object, string, item, &global_hooks, false);
20462046+ return add_item_to_object(object, string, item, &global_hooks, false);
19492047}
1950204819512049/* Add an item to an object with constant string as key */
19521952-CJSON_PUBLIC(void) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item)
20502050+CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item)
19532051{
19541954- add_item_to_object(object, string, item, &global_hooks, true);
20522052+ return add_item_to_object(object, string, item, &global_hooks, true);
19552053}
1956205419571957-CJSON_PUBLIC(void) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item)
20552055+CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item)
19582056{
19592057 if (array == NULL)
19602058 {
19611961- return;
20592059+ return false;
19622060 }
1963206119641964- add_item_to_array(array, create_reference(item, &global_hooks));
20622062+ return add_item_to_array(array, create_reference(item, &global_hooks));
19652063}
1966206419671967-CJSON_PUBLIC(void) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item)
20652065+CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item)
19682066{
19692067 if ((object == NULL) || (string == NULL))
19702068 {
19711971- return;
20692069+ return false;
19722070 }
1973207119741974- add_item_to_object(object, string, create_reference(item, &global_hooks), &global_hooks, false);
20722072+ return add_item_to_object(object, string, create_reference(item, &global_hooks), &global_hooks, false);
19752073}
1976207419772075CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name)
···20892187 return NULL;
20902188 }
2091218920922092- if (item->prev != NULL)
21902190+ if (item != parent->child)
20932191 {
20942192 /* not the first element */
20952193 item->prev->next = item->next;
···21052203 /* first element */
21062204 parent->child = item->next;
21072205 }
22062206+ else if (item->next == NULL)
22072207+ {
22082208+ /* last element */
22092209+ parent->child->prev = item->prev;
22102210+ }
22112211+21082212 /* make sure the detached item doesn't point anywhere anymore */
21092213 item->prev = NULL;
21102214 item->next = NULL;
···21522256}
2153225721542258/* Replace array/object items with new ones. */
21552155-CJSON_PUBLIC(void) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem)
22592259+CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem)
21562260{
21572261 cJSON *after_inserted = NULL;
2158226221592263 if (which < 0)
21602264 {
21612161- return;
22652265+ return false;
21622266 }
2163226721642268 after_inserted = get_array_item(array, (size_t)which);
21652269 if (after_inserted == NULL)
21662270 {
21672167- add_item_to_array(array, newitem);
21682168- return;
22712271+ return add_item_to_array(array, newitem);
21692272 }
2170227321712274 newitem->next = after_inserted;
···21792282 {
21802283 newitem->prev->next = newitem;
21812284 }
22852285+ return true;
21822286}
2183228721842288CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement)
···22002304 {
22012305 replacement->next->prev = replacement;
22022306 }
22032203- if (replacement->prev != NULL)
22042204- {
22052205- replacement->prev->next = replacement;
22062206- }
22072307 if (parent->child == item)
22082308 {
23092309+ if (parent->child->prev == parent->child)
23102310+ {
23112311+ replacement->prev = replacement;
23122312+ }
22092313 parent->child = replacement;
22102314 }
23152315+ else
23162316+ { /*
23172317+ * To find the last item in array quickly, we use prev in array.
23182318+ * We can't modify the last item's next pointer where this item was the parent's child
23192319+ */
23202320+ if (replacement->prev != NULL)
23212321+ {
23222322+ replacement->prev->next = replacement;
23232323+ }
23242324+ if (replacement->next == NULL)
23252325+ {
23262326+ parent->child->prev = replacement;
23272327+ }
23282328+ }
2211232922122330 item->next = NULL;
22132331 item->prev = NULL;
···22162334 return true;
22172335}
2218233622192219-CJSON_PUBLIC(void) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem)
23372337+CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem)
22202338{
22212339 if (which < 0)
22222340 {
22232223- return;
23412341+ return false;
22242342 }
2225234322262226- cJSON_ReplaceItemViaPointer(array, get_array_item(array, (size_t)which), newitem);
23442344+ return cJSON_ReplaceItemViaPointer(array, get_array_item(array, (size_t)which), newitem);
22272345}
2228234622292347static cJSON_bool replace_item_in_object(cJSON *object, const char *string, cJSON *replacement, cJSON_bool case_sensitive)
···22412359 replacement->string = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks);
22422360 replacement->type &= ~cJSON_StringIsConst;
2243236122442244- cJSON_ReplaceItemViaPointer(object, get_object_item(object, string, case_sensitive), replacement);
22452245-22462246- return true;
23622362+ return cJSON_ReplaceItemViaPointer(object, get_object_item(object, string, case_sensitive), replacement);
22472363}
2248236422492249-CJSON_PUBLIC(void) cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem)
23652365+CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem)
22502366{
22512251- replace_item_in_object(object, string, newitem, false);
23672367+ return replace_item_in_object(object, string, newitem, false);
22522368}
2253236922542254-CJSON_PUBLIC(void) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string, cJSON *newitem)
23702370+CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string, cJSON *newitem)
22552371{
22562256- replace_item_in_object(object, string, newitem, true);
23722372+ return replace_item_in_object(object, string, newitem, true);
22572373}
2258237422592375/* Create basic types: */
···22902406 return item;
22912407}
2292240822932293-CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool b)
24092409+CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean)
22942410{
22952411 cJSON *item = cJSON_New_Item(&global_hooks);
22962412 if(item)
22972413 {
22982298- item->type = b ? cJSON_True : cJSON_False;
24142414+ item->type = boolean ? cJSON_True : cJSON_False;
22992415 }
2300241623012417 return item;
···24302546 }
2431254724322548 a = cJSON_CreateArray();
25492549+24332550 for(i = 0; a && (i < (size_t)count); i++)
24342551 {
24352552 n = cJSON_CreateNumber(numbers[i]);
···24472564 suffix_object(p, n);
24482565 }
24492566 p = n;
25672567+ }
25682568+25692569+ if (a && a->child) {
25702570+ a->child->prev = n;
24502571 }
2451257224522573 return a;
···24852606 p = n;
24862607 }
2487260826092609+ if (a && a->child) {
26102610+ a->child->prev = n;
26112611+ }
26122612+24882613 return a;
24892614}
24902615···2502262725032628 a = cJSON_CreateArray();
2504262925052505- for(i = 0;a && (i < (size_t)count); i++)
26302630+ for(i = 0; a && (i < (size_t)count); i++)
25062631 {
25072632 n = cJSON_CreateNumber(numbers[i]);
25082633 if(!n)
···25212646 p = n;
25222647 }
2523264826492649+ if (a && a->child) {
26502650+ a->child->prev = n;
26512651+ }
26522652+25242653 return a;
25252654}
25262655···25572686 p = n;
25582687 }
2559268826892689+ if (a && a->child) {
26902690+ a->child->prev = n;
26912691+ }
26922692+25602693 return a;
25612694}
25622695···26272760 next = newchild;
26282761 }
26292762 child = child->next;
27632763+ }
27642764+ if (newitem && newitem->child)
27652765+ {
27662766+ newitem->child->prev = newchild;
26302767 }
2631276826322769 return newitem;
···2839297628402977CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive)
28412978{
28422842- if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF)) || cJSON_IsInvalid(a))
29792979+ if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF)))
28432980 {
28442981 return false;
28452982 }
···28763013 return true;
2877301428783015 case cJSON_Number:
28792879- if (a->valuedouble == b->valuedouble)
30163016+ if (compare_double(a->valuedouble, b->valuedouble))
28803017 {
28813018 return true;
28823019 }
+17-12
src/external/cjson/cjson/cJSON.h
···8181/* project version */
8282#define CJSON_VERSION_MAJOR 1
8383#define CJSON_VERSION_MINOR 7
8484-#define CJSON_VERSION_PATCH 12
8484+#define CJSON_VERSION_PATCH 15
85858686#include <stddef.h>
8787···146146/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */
147147/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */
148148CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value);
149149+CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length);
149150/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
150151/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */
151152CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated);
153153+CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated);
152154153155/* Render a cJSON entity to text for transfer/storage. */
154156CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item);
···173175/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
174176CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void);
175177176176-/* Check if the item is a string and return its valuestring */
178178+/* Check item type and return its value */
177179CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item);
180180+CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item);
178181179182/* These functions check the type of an item */
180183CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item);
···216219CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count);
217220218221/* Append item to the specified array/object. */
219219-CJSON_PUBLIC(void) cJSON_AddItemToArray(cJSON *array, cJSON *item);
220220-CJSON_PUBLIC(void) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
222222+CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item);
223223+CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
221224/* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object.
222225 * WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before
223226 * writing to `item->string` */
224224-CJSON_PUBLIC(void) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item);
227227+CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item);
225228/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
226226-CJSON_PUBLIC(void) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
227227-CJSON_PUBLIC(void) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);
229229+CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
230230+CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);
228231229232/* Remove/Detach items from Arrays/Objects. */
230233CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item);
···236239CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string);
237240238241/* Update array items. */
239239-CJSON_PUBLIC(void) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */
242242+CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */
240243CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement);
241241-CJSON_PUBLIC(void) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
242242-CJSON_PUBLIC(void) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
243243-CJSON_PUBLIC(void) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem);
244244+CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
245245+CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
246246+CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem);
244247245248/* Duplicate a cJSON item */
246249CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse);
···253256254257/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings.
255258 * The input pointer json cannot point to a read-only address area, such as a string constant,
256256- * but should point to a readable and writable adress area. */
259259+ * but should point to a readable and writable address area. */
257260CJSON_PUBLIC(void) cJSON_Minify(char *json);
258261259262/* Helper functions for creating and adding items to an object at the same time.
···273276/* helper for the cJSON_SetNumberValue macro */
274277CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
275278#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))
279279+/* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */
280280+CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring);
276281277282/* Macro for iterating over an array or object */
278283#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)