Eric Haszlakiewicz
485f2a02c7
Issue #486 : append a missing ".0" to negative double values too.
2019-05-28 02:44:22 +00:00
Eric Haszlakiewicz
ee4691c9fb
Merge pull request #453 from darjankrijan/master
...
Fixed misalignment in JSON string due to space after \n being printed...
2018-12-11 20:17:43 -05:00
Eric Haszlakiewicz
240627f260
Merge pull request #454 from ramiropolla/json_object_private
...
json_object_private: save 8 bytes in struct json_object in 64-bit arc…
2018-11-30 09:49:35 -05:00
Eric Haszlakiewicz
745cadc944
Merge pull request #461 from andy5995/issue_422
...
json_object.c:set errno in json_object_get_double()
2018-11-28 20:39:42 -05:00
andy5995
3b108935d0
json_object.h:document json_object_new_string_len()
...
I also added a couple trivial, but related, suggestions.
closes #460
2018-11-27 11:35:45 -06:00
andy5995
506a32d4ab
json_object.c:set errno in json_object_get_double()
...
closes #422
2018-11-26 21:12:06 -06:00
Ramiro Polla
5bb5e2e8fc
json_object_private: save 8 bytes in struct json_object in 64-bit architectures
...
- there is no need for _ref_count to be uint_fast32_t (the compiler
might decide to use a 64-bit int). make it uint32_t instead.
- reorder the 32-bit integer fields (o_type and _ref_count) so that
there is no wasted 4-byte gap after each of them.
2018-11-24 04:16:36 +01:00
Darjan Krijan
3943960874
Removed spaces after \n for arrays as well
2018-11-21 22:34:01 +01:00
Darjan Krijan
e8cec5c9e4
Fixed misalignment in JSON string due to space after \n being printed when choosing JSON_C_TO_STRING_SPACED together with JSON_C_TO_STRING_PRETTY in json_object_array_to_json_string
2018-11-20 22:21:27 +01:00
Eric Haszlakiewicz
f8c632f579
Issue #407 : fix incorrect casts in calls to ctype functions (isdigit and isspace) so we don't crash when asserts are enabled on certain platforms and characters > 128 are parsed.
2018-03-25 18:25:58 -04:00
Eric Haszlakiewicz
c652b6ad29
PR#394: fix breakage with VS build.
2017-12-24 14:42:58 -05:00
Eric Haszlakiewicz
d5da847f51
PR#394: don't always append the ".0" if the double value rounds to zero because some custom formats *will* include it (e.g. %.2f).
...
Also try to accomodate formats to explicitly exclude the decimal (e.g. %.0f).
2017-12-24 13:45:52 -05:00
Eric Haszlakiewicz
0992aac61f
Remove the TRUE and FALSE defines.
2017-12-23 09:42:17 -05:00
Björn Esser
c233f5c05e
json_object_private: Use unsigned 32-bit integer type for refcount
2017-12-17 12:51:17 +01:00
Björn Esser
9aca3b6a08
json_object: Avoid invalid free (and thus a segfault) when ref_count gets < 0
2017-12-14 14:36:07 +01:00
Eric Haszlakiewicz
5b6d62259a
Apply gcc's "const" attribute to the json_c_object_sizeof() function as an optimizer hint. Also, rename that function from json_object_sizeof().
2017-12-12 18:26:51 -05:00
Björn Esser
c123a1c21b
json_object: Add size_t json_object_sizeof()
2017-12-11 16:16:15 +01:00
Eric Haszlakiewicz
aedd36ac8b
Make sure to include the "*" on function pointer arguments to avoid a warnings from VS2015. See also PR#384.
2017-12-04 18:17:52 -05:00
ssrlive
2643658b6f
Update json_object.c
2017-12-04 14:46:41 +08:00
Eric Haszlakiewicz
5dae561d33
In json_object_deep_copy(), copy over _userdata, at least for json_type_string's with the default serializer set, and provide a way for people using custom serializers to provide a custom shallow_copy method.
2017-11-29 23:35:38 -05:00
Eric Haszlakiewicz
437716c5b4
Rename _set_last_err() to _json_c_set_last_err().
2017-11-29 09:36:53 -05:00
Eric Haszlakiewicz
4dd92180c6
Merge branch 'json_deep_copy' of https://github.com/commodo/json-c into commodo-json_deep_copy
2017-11-29 09:12:59 -05:00
Eric Haszlakiewicz
3628f16dd6
Rename json_object_add_int() to json_object_int_inc() and eliminate the "int64" variant since we store 64-bit values internally anyway.
2017-11-27 17:57:36 -05:00
Alexandru Ardelean
bf80d5ad0e
json_object: implement json_object_deep_copy()
...
Because doing `json_tokener_parse(json_object_get_string(src))`
feels sloppy, dirty, and makes me want to cry at night
sometimes.
Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com >
2017-11-27 16:17:48 +02:00
Juraj Vijtiuk
1110e84cce
Add json_object_add_int functions
2017-09-14 09:36:12 -04:00
Kurt Schwehr
d9879c2533
Fix double to int cast overflow in json_object_get_int64.
...
Found with autofuzz in GDAL
2017-09-11 07:23:00 -07:00
Jason King
e3fabe9a44
Add long long 64-bit check
2017-09-08 01:46:06 +00:00
Haffon
b301f4ea01
rollback api to 0.12
2017-09-07 10:02:21 +08:00
Haffon
86a3a6475f
Merge pull request #2 from json-c/master
...
merge upstream
2017-09-07 09:33:07 +08:00
Eric Haszlakiewicz
548d000891
Undo a bit of 2d1da5ab: handle per-thread formats for double serialization, even if --enable-threading wasn't specified.
2017-09-05 01:56:42 -04:00
Eric Haszlakiewicz
2d1da5ab13
Add a --enable-threading configure option, and only use the (slower) __sync_add_and_fetch()/__sync_sub_and_fetch() function when it is specified.
2017-09-03 23:37:12 -04:00
Eric Haszlakiewicz
5b11e9adff
Explicitly check for GCC's atomic functions instead of depending on the __GNUC__ define.
...
Add a comment mentioning the limitation even though the _ref_count value is hanled atomically.
2017-09-02 14:48:17 -04:00
Eric Haszlakiewicz
ab0d4dbc69
Merge branch 'pull-211'
...
This is EmielBruijntes' "Atomic updates for the refcount"
2017-09-02 13:54:15 -04:00
Haffon
95e174e2fb
Merge pull request #1 from json-c/master
...
want to merge the original repository
2017-08-30 00:02:59 +08:00
Eric Haszlakiewicz
81f6edbfd5
PR#331: for Visual Studio, use a snprintf/vsnprintf wrapper that ensures the string is terminated.
2017-08-25 01:15:39 -04:00
Haffon
3141c3976b
1.make it can been compiled with Visual Studio 2010
...
2.replace json_object_get/put API with json_object_retain/release, as they operate the reference counter, and confused with array_list_get/put_idx.
3.replace array_list_get/put_idx API with array_list_get/insert to make them more clear to use.
2017-08-22 13:53:47 +08:00
Kurt Schwehr
ef7b08ce7f
Clamp double to int32 when narrowing in json_object_get_int.
...
Avoids undefined behavior. Found by autofuzz.
2017-08-08 07:54:38 -07:00
Alexandru Ardelean
fb72160caf
build: make strerror() override-able
...
If we want to override `strerror()` in libjson-c
to make tests consistent across platforms, we
need to do it build-wide as configure/build
option.
Apple linkers make it really hard to override functions
at link-time, and this seems to be locked down on travis-ci.org
[ for security reasons I assume ].
While I got it to work locally, it did not work
when running on travis.
Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com >
2017-07-13 10:27:24 +03:00
Eric Haszlakiewicz
b64402ede2
Move a variable declaration to the start of the block to work better with older compilers.
2017-07-09 16:09:09 -07:00
Eric Haszlakiewicz
f7a44ad101
Add extra casts to void * to squash some warning on certain systems (e.g. CentOS w/ gcc 4.1.2).
2017-07-09 15:08:21 -07:00
Eric Haszlakiewicz
7b7a76e161
Fix bad usage of strncat introduces in 1a94c70. Pointed out by @rouault in PR #331 .
2017-07-09 15:04:18 -07:00
Eric Haszlakiewicz
55ecae3e58
Eliminate static qualifiers on a couple local variables that were causing thread safety issues. Suggested by @rouault in PR #331 .
2017-07-09 14:56:18 -07:00
Eric Haszlakiewicz
5a99e527ff
Reformat json_object_double_to_json_string_format() to have consistent spacing.
2017-07-08 20:33:28 -07:00
Eric Haszlakiewicz
1a94c70336
Add a json_c_set_serialization_double_format() function to set the *library-wide* format for how doubles are written to a serialized JSON output.
2017-06-18 18:12:07 +00:00
Even Rouault
2c2deb87f8
Fix stack buffer overflow in json_object_double_to_json_string_format()
...
Issue originally found in the json-c 0.11 internal copy in GDAL but also found
in latest git version.
If doing things like
json_object* obj = json_object_new_double(1e300);
json_object_set_serializer(obj, json_object_double_to_json_string, "%f", NULL);
json_object_to_json_string(obj)
size = snprintf(buf, sizeof(buf),
format ? format :
(modf(jso->o.c_double, &dummy) == 0) ? "%.17g.0" : "%.17g",
jso->o.c_double);
will return a value greater than 128 since at least 300 characters are needed.
This value is then passed to printbuf_memappend(pb, buf, size); that tries to
read size bytes in buf.
So we should clamp size to sizeof(buf). And on Windows, _snprintf() returns -1
in that situation, so deal also with this case.
Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=1682
Credit to OSS-Fuzz
2017-05-18 22:36:35 +02:00
Jason Li
0f81ecf5f4
Fix error C3688 when compiling on Visual Studio 2015: invalid literal suffix 'PRId64'; literal operator or literal operator template 'operator ""PRId64' not found
2017-03-24 14:53:25 +08:00
marxin
014924ba89
Add FALLTHRU comment to handle GCC7 warnings.
2017-03-21 08:42:11 +01:00
Quentin Young
f6f852fd93
Restore sprintbuf(), add macro for string literals
...
Hawciz pointed out that the previous commit modifies the public
interface of printbuf. Per his suggestion, sprintbuf() was restored
and a new pair of macros was added that wraps printbuf_memappend().
Using a wrapper macro instead of modifying sprintbuf() also reduces
function call overhead, bringing total performance gains to
approximately 400%.
2017-02-04 01:02:00 +00:00
Quentin Young
9ff0f4987f
Improve json_object -> string performance
...
Removes variadic prints for ~3x performance improvement.
2017-02-02 17:33:54 +00:00
Jan Gerhards
ca7a1973e2
bugfix: floating point representaion without fractional part
...
closes https://github.com/json-c/json-c/issues/278
2016-11-27 11:47:00 +01:00