1
0
mirror of https://github.com/kgabis/parson.git synced 2025-01-28 06:32:55 +08:00

104 Commits

Author SHA1 Message Date
Krzysztof Gabis
ba29f4eda9 1.5.3: Fixes compilation on mac os (due to sprintf being deprecated) #209 2023-10-31 20:44:37 +01:00
Valerie Avva Lim
60c37844d7
1.5.2: fix Arithmetic overflow (#204)
* fix Arithmetic overflow

* address PR comment and update version
2023-05-21 10:15:39 +02:00
Krzysztof Gabis
3c4ee26dbb 1.5.1: Fixes a bug in json_object_clear.
Issue #200
2023-02-15 22:59:21 +01:00
Alexandru Ardelean
1314bf8ad6
1.5.0: Using memcpy instead of sprintf for string literals, adds json_set_number_serialization_function 2022-11-12 22:00:17 +01:00
Krzysztof Gabis
a34e725282 1.4.0: Accepting trailing commas in objects and arrays
Issue #178
2022-03-06 21:27:20 +01:00
Cristian Pop
4158fdbea7
1.3.1: Fixes size_t conversion on x64 systems. Excluding build/ in .gitignore. (#177)
* Fixing size_t conversion on x64 systems. Excluding build/ in .gitignore.

* 1.3.1: Increments version.

Co-authored-by: Krzysztof Gabis <kgabis@gmail.com>
2022-02-24 20:22:46 +01:00
Krzysztof Gabis
4bd5797811 Fixes repository URL
#176
2022-02-18 21:28:25 +01:00
Krzysztof Gabis
6e30db3599 Updates license (version and year). 2022-01-26 12:14:25 +01:00
Krzysztof Gabis
af848c27b4 1.3.0: Adds json_set_float_serialization_format function. 2021-12-11 18:11:18 +01:00
Krzysztof Gabis
fd77bcddc1 1.2.1: Not using SIZE_MAX macro (issue #167) 2021-08-06 15:46:45 +02:00
Krzysztof Gabis
6b3d6f42f2 1.2.0: JSON objects are now implemented using hash maps, PARSON_VERSION defines (issue #37) 2021-08-05 20:24:57 +02:00
Krzysztof Gabis
2d7b3ddf12 1.1.3: Ignoring floating point underflow (issue #161) 2021-05-26 14:01:51 +02:00
Disconnect3d
ab7f5e5401
Fix memleak when parsing keys with embedded null bytes (#157)
* Fix memleak when parsing key with embedded null byte

This commit fixes and adds a test for a memory leak that occurs when
parsing strings with keys that have a null byte embedded in them.

This memory leak can be triggered with the following line, where this
call returns a `NULL`:
```c
        json_parse_string("{\"\\u0000\"")
```

This memory leak happens in the `parse_object_value` function in here:
```
        new_key = get_quoted_string(string, &key_len);  <---- ALLOCATION
        /* We do not support key names with embedded \0 chars */
        if (new_key == NULL || key_len != strlen(new_key)) {
            json_value_free(output_value);
            return NULL;                       <---- `new_key` NOT FREED
        }
        SKIP_WHITESPACES(string);
        if (**string != ':') {
            parson_free(new_key);
            json_value_free(output_value);
            return NULL;
        }
```

* Increments version to 1.1.2

Co-authored-by: Krzysztof Gabis <kgabis@gmail.com>
2021-05-03 18:47:03 +02:00
benswick
60b2c69f17
Improved serialization performance (#156)
* Update parson.c

Get objects by index instead of key in json_serialize_to_buffer_r().

* Increments version and updates licence date.

Co-authored-by: Krzysztof Gabis <kgabis@gmail.com>
2021-04-07 22:23:01 +02:00
reuben olinsky
102a4467e1
Add support for string values with embedded '\0' characters (#137)
* Add support for strings with \0 chars

* address feedback

* Increments minor version, adds comments, changes license year

Co-authored-by: Krzysztof Gabis <kgabis@gmail.com>
2020-04-16 21:55:56 +02:00
ɹɐɯsǝʎ
186680a511 Guard against potential integer overflow (#133)
* Guard against potential integer overflow

If int res holds the value INT_MAX then adding 1 results in undefined
behavior. To guard against this possibility, cast res to size_t, not
the result of res + 1.

Fixes #132

* Increments version.

* More consitent parentheses when casting to size_t.
2019-12-03 10:59:32 +01:00
dan soucy
9d63e76014 Avoid truncating strings warning (#131)
* Avoid truncating strings warning

GCC 8 introduced the `stringop-truncation` warning, which warns for
uses of `strncpy` of the form `strncpy(out, in, strlen(in))`. This
is often helpful, as this call would not copy the trailing `\0`,
potentially leading to subtle bugs.

With optimizations enabled, the function `parson_strndup` is
inlined, allowing the compiler to see that this call to `strncpy` is
of the form described above. GCC therefore outputs the warning.

In this case, the out buffer has already had the terminating `\0`
written to the end. Thus it is not necessary to copy it. GCC 9.2 is
not quite smart enough to recognize this, so it warns.

The warning is silenced by using `memcpy` instead of `strncpy`.

Although I have not benchmarked it, this change might reasonably
improve the performance of `parson_strndup`. `strncpy` checks every
byte for `\0` in addition to counting to `n`. `memcpy` does not need
to check whether the bytes it copies are `\0`.

However, if `parson_strndup` is frequently passed `char *`s with a
`\0` somewhere in the middle, then `memcpy` will copy more bytes
than necessary, hurting performance. In this case, a better solution
might be:

```
- output_string[n] = `\0`;
- strncpy(output_string, string, n);
+ strncpy(output_string, string, n+1);
```

* Increments parson's version.
2019-12-02 23:24:29 +01:00
Krzysztof Gabis
0341880552 Using semantic versioning from now on, Parson is officially 1.0.0 2019-11-28 10:12:03 +01:00
Dan Ellis
9e1de5086f Fix memory leaks in parson_object_set_* when object is invalid 2019-11-11 14:05:45 -08:00
Krzysztof Gabis
c5bb9557fe Updates copyright year. 2019-07-11 18:33:44 +02:00
Akihiro Suda
9ec77a8d74 add SPDX-License-Identifier
SPDX-License-Identifier is useful to clarify the license (both for humans and
machines), especially when the code of the project is embedded into other
projects.

ref: https://spdx.org/using-spdx-license-identifier

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2019-07-11 21:23:37 +09:00
Krzysztof Gabis
302fba9cbb Makes escaping slashes when serializing JSON optional (adds json_set_escape_slashes() function)
Issues #20 #34 #90
2018-11-26 20:12:16 +01:00
Krzysztof Gabis
b58ac757a8 Using isnan and isinf macros if they are defined (fixes issue #104). 2018-08-02 21:20:39 +02:00
Krzysztof Gabis
4f3eaa6849 Not adding incorrect objects if json_object_dotset_value() fails halfway through.
Related to issue #100
2018-05-12 17:42:14 +02:00
Krzysztof Gabis
921da6f5d7 Using smaller buffer size for number serialization.
Issue #88 and #61
2018-04-15 17:39:56 +02:00
Krzysztof Gabis
387c5665f6 Better handling of CRLF line breaks. 2018-02-06 20:32:02 +01:00
Roy Sprowl
385b476a30 Fix signed char fed to isspace 2017-12-07 21:51:47 -08:00
Roman Kalashnikov
f1bb6e7fbe
Fixed condition 2017-10-28 01:23:15 +03:00
Krzysztof Gabis
4e8a901242 Changes float print format, removes array/object capacity limit, doesn't accept inf/nan numbers. 2017-09-16 16:07:43 +01:00
Krzysztof Gabis
e1292a0e3c Small refactoring in parse_utf16 (+ tests) and typo fix in json_array_remove. 2017-09-14 10:00:24 +01:00
Krzysztof Gabis
343fe13f17 Order of items in an array is preserved after removing an item.
Issue #81
2017-09-06 10:02:52 +01:00
Krzysztof Gabis
d485b068c7 Fixes a memory leak (issue #82). 2017-09-04 19:56:17 +01:00
Krzysztof Gabis
e410fc7c33 Increases MAX_NESTING of json objects/arrays to 2048.
Fixes #75
2017-05-08 19:55:29 +01:00
Krzysztof Gabis
20ad63f8ff Fixes memory leaks.
Thanks to Thales de Carvalho for finding this and submitting a patch.
2017-03-09 20:59:22 +00:00
Krzysztof Gabis
ba2a854c27 Fixes undefined behaviour as reported by clang ub sanitizer.
Issue #72
2017-03-01 19:33:40 +00:00
Krzysztof Gabis
2bfa4153db Updates copyright. 2017-02-18 16:41:14 +00:00
Krzysztof Gabis
96150ba1fd Removes dependency on sscanf and prints line numbers in tests output.
Some libraries don't have sscanf and since it wasn't used heavily it was easily replaced with a custom function. This doesn't mean that sscanf won't be used in future though (but I'll try to avoid it).
Fixes #68. Thanks to @compulim for initial work on this issue.
2017-02-18 15:26:22 +00:00
Krzysztof Gabis
cb14736e96 Checking errno after strtod call. 2017-01-06 21:35:29 +01:00
Krzysztof Gabis
defb57f2d3 Some extra null checks (issue #60). 2016-12-30 23:04:14 +01:00
Krzysztof Gabis
f419334a32 Adds links to parent values and values used to wrap objects/arrays. Assigning a value to 2 objects/arrays returns an error now.
Addresses issues #66 and #30.
2016-12-29 23:50:20 +01:00
Krzysztof Gabis
dcf85b88c8 Support for UTF-8 with BOM.
Fixes #65
2016-12-08 21:40:52 +00:00
Jean-Marie Lemetayer
d198f6ebfe Add support to print unsigned integers
Else numbers between INT_MAX and UINT_MAX will be printed using double format
2016-09-20 16:48:13 +02:00
t-k-
7b90bbbf24 Further escape \x00 - \x1F control characters. 2016-09-08 21:01:02 +08:00
Krzysztof Gabis
c22be794ce Using braces in every if statement + whitespace cleanup. 2016-08-23 20:57:10 +01:00
Krzysztof Gabis
a1c356eaa9 Adds functions to check if object has value with a certain name (and optionally type).
This closes #42.
2016-07-05 12:23:17 +02:00
Krzysztof Gabis
bcefc459dd Changes skip_quotes return type to JSON_Status. 2016-07-05 11:52:24 +02:00
Krzysztof Gabis
8075050bc1 Fixes #43 2016-07-05 11:45:41 +02:00
Jacob Enget
1c1b77aa7e Fixes typo causing problems with array element validation 2016-06-06 13:45:14 -05:00
Krzysztof Gabis
5c4a11b036 Removes trailing whitespace. 2016-04-23 12:11:25 +02:00
Krzysztof Gabis
473c7f3d8d Adds json_object_get_value_at function to access values in objects in O(1) time.
Also adds some missing null checking.
2016-04-23 11:59:34 +02:00