Commit Graph

232 Commits

Author SHA1 Message Date
Max Bruckner
c26d53f0d7 Helper function to check the type of an item
This is necessary, because you can get it wrong if you do it manually.
(when you forget the & 0xFF in the comparison)
2017-02-26 14:30:50 +01:00
Max Bruckner
501046247d fix clang-sanitizer warnings 2017-02-21 15:08:36 +01:00
Max Bruckner
68cd0d4a11 cJSON.c: Pass allocation functions through internal functions
This is the first step in removing the global allocator functions. Every
internal function now only accesses its locally available set of
allocators.
2017-02-21 14:50:49 +01:00
Max Bruckner
605422c60a cJSON: New function cJSON_GetObjectItemCaseSensitive 2017-02-21 11:17:08 +01:00
Max Bruckner
1d42c9bc60 print_object: simplify code 2017-02-20 23:07:24 +01:00
Max Bruckner
b71db93e03 print_object: rename variables 2017-02-20 23:07:24 +01:00
Max Bruckner
6d5a7c8c40 print_array: simplify code 2017-02-20 23:07:24 +01:00
Max Bruckner
8c1ed3ab82 update: rename to update_offset and change offset directly 2017-02-20 23:07:24 +01:00
Max Bruckner
f16dd7e028 print_array: rename variables 2017-02-20 23:07:24 +01:00
Max Bruckner
08770fc246 print_value: rename variables 2017-02-20 23:07:23 +01:00
Max Bruckner
0ca8587acc print_string_ptr: simplify code 2017-02-20 23:07:23 +01:00
Max Bruckner
6a746a230a print_string: Add more const 2017-02-20 23:07:23 +01:00
Max Bruckner
1e999352d3 print_string_ptr: rename variables 2017-02-20 23:07:23 +01:00
Max Bruckner
6815d96617 print_number: rename variables 2017-02-20 23:07:22 +01:00
Max Bruckner
61921498d0 print_number: remove special case for 0
Now that printbuffer is used for everything, it's not needed anymore.
2017-02-20 23:07:22 +01:00
Max Bruckner
3c4d309f62 ensure: Don't accept empty printbuffers anymore 2017-02-19 04:20:21 +01:00
Max Bruckner
9bf531ca05 Remove printing without buffer 2017-02-19 04:16:57 +01:00
Max Bruckner
80354bdb06 cJSON_Print: Use printbuffer 2017-02-19 04:03:02 +01:00
Max Bruckner
331c18d09a ensure: only memcopy what's necessary
We don't need to copy the entire printbuffer, only the part that is
used.
2017-02-18 12:07:17 +01:00
Max Bruckner
4fff92140e ensure: use realloc if possible 2017-02-18 12:07:17 +01:00
Max Bruckner
fc1d4b07df ensure: if printbuffer is null: cJSON_malloc
This allowed for the removal of a lot of if (p) checks.
2017-02-18 11:35:59 +01:00
Max Bruckner
bd073343fa rename skip -> skip_whitespace 2017-02-17 19:37:31 +01:00
Max Bruckner
4fce9cce86 Release version 1.3.0 2017-02-17 01:42:02 +01:00
Max Bruckner
b41264d164 Remove uint8_t because it's not part of C89 2017-02-16 21:22:43 +01:00
Max Bruckner
0f271dcf63 parse_hex4: make input pointer const 2017-02-16 21:02:26 +01:00
Max Bruckner
ead389aba2 parse_value: improve variable names + const correctness 2017-02-16 21:02:25 +01:00
Max Bruckner
698dc528f4 parse_object: improve variable names + const correctness 2017-02-16 21:02:25 +01:00
Max Bruckner
3dc6339025 parse_array: improve variable names + const correctness 2017-02-16 20:08:59 +01:00
Max Bruckner
15592c50f6 parse_number: improve variable names + const correctness 2017-02-16 20:02:18 +01:00
Max Bruckner
efb5e1bc93 parse_string: Improve const correctnes of pointers 2017-02-16 20:00:12 +01:00
Max Bruckner
ace5047782 parse_string: reduce mental burden when reading the code
This restructures parse_string in a way, that you need to keep less
state in your head to understand the code.

This is achieved by:
* only changing the input pointer (current position) at a few places
(not all throughout)
* splitting out the UTF16 handling into a separate function
* renaming the variables so you know what they do without additional
context
2017-02-16 19:49:03 +01:00
Max Bruckner
03f23738bb parse_object: simplify to one do-while loop 2017-02-16 19:49:02 +01:00
Max Bruckner
24dbf29360 parse_array: simplify to one do-while loop 2017-02-16 19:49:02 +01:00
Max Bruckner
12b2daccf3 parse_{object,array}: set child only after parsing
This only attaches the parsed linked lists to the items passed to
parse_object and parse_array.
2017-02-16 01:03:43 +01:00
Max Bruckner
f8d0c47bdb Remove unnecessary assignment and silence clang analyzer 2017-02-16 00:31:57 +01:00
Max Bruckner
9f6fa94c91 ensure: replace pow2gt with multiplication by two
This replaces the bit fiddling involved with calculating a new buffer
size by just multiplying the required length by two, paving the way to a
complete switch to size_t at a later point in time.
2017-02-16 00:23:38 +01:00
Max Bruckner
123bb1af7b cJSON: prevent incompatible C and header versions
Introduces a preprocessor directive that aborts the compilation if the
version numbers in the header don't match with the numbers in the c
file.
2017-02-15 23:21:50 +01:00
Max Bruckner
cf862d0fed implement AddItemToObject using AddItemToObjectCS 2017-02-15 21:46:24 +01:00
Max Bruckner
3facca4792 parse functions: Only set type after successful
This sets the type of an item only if parsing was successful.

This means that in case of failure, the item's type will remain to be
cJSON_Invalid.
2017-02-15 21:25:48 +01:00
Max Bruckner
702fd95af3 fix #106: potentially invalid free in cJSON_AddItemToObject 2017-02-15 20:45:23 +01:00
Max Bruckner
94117a5d23 Fix #105, double free when parse_string fails
This fixes a double free that happens when calling cJSON_Delete on an
item that has been used by parse_string and it failed parsing the
string.

The double free happens, because parse_string frees an alias of
item->valuestring, but doesn't set item->valuestring to NULL.
2017-02-15 15:37:38 +01:00
Max Bruckner
4047de4f6e fix potential NULL dereferences found by coverity 2017-02-08 03:00:44 +01:00
Max Bruckner
87f77274de cJSON_SetNumberValue: Fix undefined double to int conversion
This might cause slight changes in behavior, but it shouldn't break
anything that is not already broken (for example the original macro
could either return a double, or an integer or whatever depending on if
object is NULL or not.)
2017-02-07 21:23:36 +01:00
Max Bruckner
dded751757 parse_string: remove useless first byte marks for utf8 2017-02-07 21:23:36 +01:00
Max Bruckner
d7b5545748 parse_hex4: deduplicate into a for loop 2017-02-07 21:23:36 +01:00
Max Bruckner
0747669972 parse_number: Switch to C library's strtod
Replaces the hand written floating point parser with the C library
implementation.
2017-02-07 21:23:36 +01:00
Max Bruckner
cc514583cc cJSON_Duplicate: goto fail error handling
Simplify error handling using goto fail and improve some names.
2017-02-07 20:59:55 +01:00
Max Bruckner
021b174ee1 parse_object: goto fail error handling
Makes the control flow easier to reason about and fixes a few potential
memory leaks.
2017-02-07 20:59:55 +01:00
Max Bruckner
99cd9af7d5 parse_array: goto fail error handling
Makes the control flow easier to reason about and fixes a few potential
memory leaks.
2017-02-07 20:59:55 +01:00
Max Bruckner
8656386c4f parse_string: goto fail error handling
Makes the control flow easier to reason about and fixes a few potential
memory leaks.
2017-02-07 20:59:55 +01:00