Commit Graph

134 Commits

Author SHA1 Message Date
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
Alexandru Ardelean
8cb86a583a strdup_compat.h: re-spin this compat header ; use math_compat.h as template
Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
2016-11-22 16:37:29 +02:00
Emmanuele Bassi
7601f20d70 Revert "compat/strdup.h: move common compat check for strdup() to own file"
This reverts commit aaba8c1080.

This commit breaks builddir != srcdir build, but, more importantly, it
also adds a dependency on a header, "config.h", which is not installed
and it's supposed to be private — since it's generated at configuration
time and it's not meant to be used by projects compiling against a
library.
2016-11-07 20:51:11 +00:00
Alexandru Ardelean
aaba8c1080 compat/strdup.h: move common compat check for strdup() to own file
Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
2016-11-03 15:51:33 +02:00
Eric Haszlakiewicz
d4899bd4d5 Handle NULL objects in json_object_get_userdata() by returning NULL, but abort in json_object_set_userdata() since we can't actually do anything with the userdata. 2016-10-29 15:42:36 -04:00
Eric Haszlakiewicz
f8132f932d Issue #280: add a few assert() calls to ensure objects are of the appropriate type. 2016-10-29 15:31:31 -04:00
Eric Haszlakiewicz
818156f6f7 Merge pull request #277 from ALLTERCO/json_object_set_xxx
Json object set xxx
2016-10-08 12:08:53 -04:00
Stoian Ivanov
be63ba99ca try restore windows automated builds 2016-10-07 22:54:06 +03:00
Stoian Ivanov
a26305d428 fix compiler warning for int sizes 2016-10-07 01:07:34 +03:00
Stoian Ivanov
e518b22b72 string set and tests 2016-10-07 00:51:24 +03:00
Stoian Ivanov
05f025c075 some basic set 2016-10-05 23:55:46 +03:00
Alexey Konovalov
b2fbf93df0 fixed wrong object name in json_object_all_values_equal 2016-09-27 11:20:49 +03:00
Stoian Ivanov
fae09456ae json_object_set_boolean for upstream style check 2016-09-21 01:31:00 +03:00
Eric Haszlakiewicz
5fccfed4f4 Issue #260: add a check to prevent trivial loops in the object tree, even though it is up to the callers to avoid doing so in more complex cases. 2016-08-20 22:42:59 -04:00
Eric Haszlakiewicz
c4d060bf80 json_object_object_add_ex() should have shared code with json_object_object_add(), and been changed to return int at the same time the latter was. Do that now.
Also correct a couple of calls to _to_json_string to check the return value.
2016-08-20 22:42:59 -04:00
Eric Haszlakiewicz
4d62de3898 Revert bogus change to json_object_get() made in f40b08d8 that caused it to always return NULL. (Issue #259)
Also undo NULL check in json_tokener_set_flags(): it's not at all valid toi
 try to set flags on a NULL pointer, and doing so should not be silently
 ignored.
2016-08-11 17:05:41 -04:00
Eric Haszlakiewicz
0ad87649d4 Merge pull request #255 from RyDroid/minor-c2
Minor changes in C source code
2016-08-10 15:06:30 -04:00
Nicola Spanti (RyDroid)
f40b08d8f0 Minor changes in C source code 2016-08-08 15:20:41 +02:00
jobol
344009bf26 Add method 'json_object_to_json_string_length'
This new method allows to also
get the length of the generated string.

Fix #165

Change-Id: Iea91404027f143ca3d29a4c58d7c07ae53556110
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
2016-07-27 14:45:25 +02:00
Eric Haszlakiewicz
595891729e Issue #236: Add -Wcast-qual and fix casts to retain constness.
To better distinguish between entry->k and entry->v being const within linkhash, but non-const outside, add lh_entry_v() and lh_entry_k() accessors.
Make lh_entry->k const.
2016-06-11 18:19:39 +00:00
Matthias Schiffer
f87e378d48 Add public API to get and set userdata
Also, json_object_set_serializer is changed to respect the userdata
and user_delete parameters when to_string_func is NULL.
2016-05-29 11:24:55 +02:00
Matthias Schiffer
c2b004ba0e Make default double serializer ignore userdata again
The user might want to use the userdata for something different, so the
serializer should ignore it by default.

Explicitly setting the serializer to json_object_double_to_json_string will
still make it interpret the userdata as a format string.
2016-05-29 11:24:55 +02:00
Eric Haszlakiewicz
996be85843 Fix a few places that needed adjustment for the size_t changes, including updating the range checks to use a calculated SIZE_T_MAX. 2016-05-23 02:10:58 +00:00
Eric Haszlakiewicz
9a2915ce66 Merge branch 'fixes-for-upstream' of https://github.com/doctaweeks/json-c into doctaweeks-fixes-for-upstream 2016-05-23 02:08:28 +00:00
Jan-Philipp Litza
21dc5dc92b Export json_object_double_to_json_string() and use custom format string 2016-05-06 16:12:44 +02:00
Eric Haszlakiewicz
1fb87cd196 Merge branch 'master' of https://github.com/Protovision/json-c into Protovision-master 2016-04-30 18:52:47 +00:00