63 Commits

Author SHA1 Message Date
Careles
51bcdd0000 fix macro WIN32_LEAN_AND_MEAN redefined
json-c as add_subdirectory and project cmakelists.txt has add_definitions(-DWIN32_LEAN_AND_MEAN)
2025-01-06 10:56:53 +08:00
Rosen Penev
66f7869219 rename WIN32 to _WIN32
The latter is the proper macro defined by Windows headers.

Fixes compilation under at least clang-cl which mandates function
declarations.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2024-02-07 18:06:55 -08:00
Eric Haszlakiewicz
c50bf9df9c Apply same EINVAL handling to json_parse_uint64() as was done for json_parse_int64(). Document that overflow/underflow for these functions is not an error, but sets errno=ERANGE. 2022-10-30 03:25:32 +00:00
Eric Haszlakiewicz
57bef5edc4 Issue #792 - set errno=EINVAL if parsing the string in json_parse_int64 fails, to match the docs for json_object_get_int. 2022-10-26 02:19:38 +00:00
Khem Raj
6eca65617a Fix build with clang-15+
Fixes
json_util.c:63:35: error: a function declaration without a prototype is deprecated in all versions of C [-We
rror,-Wstrict-prototypes]
const char *json_util_get_last_err()
                                  ^
                                   void

Signed-off-by: Khem Raj <raj.khem@gmail.com>
2022-08-13 20:47:20 -07:00
Eric Haszlakiewicz
bdd5e03d6e Apply some of the fixes from PR #740, although by using size_t instead of castings. 2022-07-31 19:28:48 +00:00
Tobias Stoeckmann
5accae04bb json_object_from_fd_ex: fail if file is too large
If the input file is too large to fit into a printbuf then return an
error value instead of silently truncating the parsed content.

This introduces errno handling into printbuf to distinguish between an
input file being too large and running out of memory.
2022-03-20 13:17:37 +01:00
Tobias Stoeckmann
6e533471a8 Fix error messages
Error messages did not reflect actual function names.
2022-03-19 10:59:43 +01:00
Even Rouault
f2c0df404b json_type_to_name(): use correct printf() formatter
Was detected by Coverity Scan when analyzing GDAL's code base which has
a copy of json-c
2022-01-31 00:27:41 +01:00
Eric Haszlakiewicz
8c7849e6e3 Eliminate use of ctype.h and replace isdigit() and tolower() with non-locale-sensitive approaches. 2020-08-02 04:06:44 +00:00
Eric Haszlakiewicz
6eac6986c9 Fix incremental parsing of invalid numbers with exponents, such as "0e+-" and "12.3E12E12", while still allowing "0e+" in non-strict mode.
Deprecate the json_parse_double() function from json_util.h
2020-06-27 15:35:04 +00:00
Pierce Lopez
003b58782b fix json_parse_uint64() usage of errno
introduced in #542
fixes #601
2020-05-10 13:38:12 -04:00
Eric Haszlakiewicz
ecb9354bb1 Re-do clang-format. 2020-04-18 02:14:13 +00:00
Eric Haszlakiewicz
23ddcbd4da Make json_abort() internal to json_object.c 2020-04-18 02:05:37 +00:00
Eric Haszlakiewicz
545464322b Issue #568: fix the strtoll and strtoull handing so config.h ends up creating defines for those only when needed, which should exclude mingw environments. 2020-04-09 20:58:28 +00:00
dota17
8b162c4b89 clang-format the files 2020-04-03 11:39:30 +08:00
dota17
c117d8a8a8 add the disabling formatting coments and adjust the partial code manuly 2020-04-03 11:28:04 +08:00
Jehan
b15e7ba470 Fixes various Wreturn-type and Wimplicit-fallthrough errors on Mingw-w64
This is a recent regression since commit
6359b79847 which added various assert(0)
calls (often replacing return-s).
With Ming-W64 compiler, json-c build was failing with various errors of
the sort:

> /home/jehan/dev/src/json-c/json_object.c: In function 'json_object_int_inc':
> /home/jehan/dev/src/json-c/json_object.c:841:1: error: control reaches end of non-void function [-Werror=return-type]
>   841 | }
>       | ^
> In file included from /home/jehan/dev/src/json-c/json_object.c:17:
> /home/jehan/dev/src/json-c/json_object.c: In function 'json_object_get_double':
> /home/jehan/.local/share/crossroad/roads/w64/json-c/include/assert.h:76:4: error: this statement may fall through [-Werror=implicit-fallthrough=]
>    76 |   (_assert(#_Expression,__FILE__,__LINE__),0))
>       |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> /home/jehan/dev/src/json-c/json_object.c:1070:7: note: in expansion of macro 'assert'
>  1070 |       assert(0);
>       |       ^~~~~~
> /home/jehan/dev/src/json-c/json_object.c:1072:3: note: here
>  1072 |   case json_type_boolean:
>       |   ^~~~

The problem is that Mingw-w64 does not consider assert() as a noreturn
(even assert(0)), because it has to be compatible by Microsoft
libraries. See the discussion here:
https://sourceforge.net/p/mingw-w64/bugs/306/

Instead let's create a new json_abort() function which is basically just
an abort() function with an optional message, for such cases where
abortion was non-conditional (using assert() and using the assertion
condition as a message here was clearly a misuse of the function). And
mark json_abort() as 'noreturn', as well as 'cold' for optimization
purpose (this is code we expect to never run, unless there is a bug,
that is).

Finally let's use this json_abort() instead of previous misused assert()
calls.
2020-03-16 19:53:28 +01:00
dota17
c816de212b modify the json_object, replace c_int64/c_uint64 with struct{union{int64, uint64},...} 2020-02-27 10:26:27 +08:00
dota17
3c3b5920f7 add uint64 data to json-c 2020-02-25 14:51:35 +08:00
Eric Haszlakiewicz
af8dd4a307 Define vars earlier to fix old Windows builds. 2019-11-10 20:35:30 -05:00
Eric Haszlakiewicz
baed9983b3 Add a json_object_from_fd_ex() function, to allow the max nesting depth to be specified. 2019-11-10 00:14:44 -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
05c85ddc21 On VS 2013 and newer, actually use strtoll instead of redefining it to _strtoi64. 2017-11-26 14:17:17 -05:00
Alexandru Ardelean
03f3b95248 json_util: define strtoll as _strtoi64 for MSVC
Got the idea from this blog post:
  http://www.enchantedage.com/node/231

Simple & concise stuff :)

Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
2017-11-07 16:51:01 +02:00
Jason King
5355d387e9 Use strtoll to parse ints 2017-09-07 17:21:14 +00:00
Eric Haszlakiewicz
b2afca4560 Issue #173: since some sscanf implementations return 0 for non-zero inputs, directly check for "0" in the input. 2017-09-05 01:53:13 -04: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
topilski
65884f4d9e Fix parsing doubles for mingw 2017-07-30 07:30:05 +03: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
e8e574fbe4 Issue #161: add a json_object_to_fd() function. 2017-06-18 18:44:45 +00:00
Eric Haszlakiewicz
8581806558 Make _set_last_err() non-static so it can be used outside of json_util.c 2017-06-18 18:11:17 +00:00
Eric Haszlakiewicz
29ef73f21d Issue #189: Eliminate use of MC_ERROR from json_util.c, and add a json_util_get_last_err() function to retrieve the error for those callers that care about it.
Add tests and descriptions for the functions in json_util.c
2016-06-26 02:20:33 +00:00
Michael Heimpold
a7534dbb7e Introduce json_object_from_fd
Also refactor json_object_from_file to use json_object_from_fd
internally.

Signed-off-by: Michael Heimpold <mhei@heimpold.de>
2014-07-21 23:15:45 +02:00
Eric Haszlakiewicz
d4e81f9ec8 Move the json_min() and json_max() macros to json_util.h and mark everything else in bits.h deprecated.
Eliminate all uses of bits.h within the json-c code.
2014-05-04 22:33:26 -04:00
Pascal Bach
20e4708c8a Update json_util
filename should be passed as const char* to functions
json_object_to_file and json_object_to_file
2013-08-13 18:27:02 +02:00
Eric Haszlakiewicz
b3bce4d594 Eliminate use of MC_ABORT in json-c code, and mark MC_ABORT/mc_abort deprecated.
Also adjust an error message in json_util to make it unique.  Fixes #87.
2013-06-29 15:31:18 -05:00
Anatol Belski
990fa8e3ee Fix C89 compat needed by MSVC 2013-06-04 20:18:28 +02:00
Eric Haszlakiewicz
5b36a432c8 Merge branch 'remicollet-issue-float'
Conflicts:
	json_util.c
2013-02-26 21:09:10 -06:00
Eric Haszlakiewicz
bfb329223a Add a runtime check to see if parse_int64 needs to workaround sscanf bugs. If that workaround is not needed parsing is nearly twice as fast. 2013-02-09 17:35:33 -06:00
Eric Haszlakiewicz
ca8b27d183 Enable -Werror and fix a number of minor warnings that existed. 2013-02-09 16:35:24 -06:00
Greg Hazel
77d0493b70 rename _errno 2013-01-03 16:54:04 -08:00
Remi Collet
a01b659ace move locale change to be global for perf 2012-12-13 09:47:33 +01:00
Remi Collet
16a4a32e29 float parsing must be locale independent 2012-11-27 11:06:49 +01:00
Eric Haszlakiewicz
77c6239465 Initialize errno before calling sscanf in json_parse_int64() so parsing valid numbers after parsing an out of range number works. 2012-07-29 12:13:54 -05:00
Eric Haszlakiewicz
eead1a7dc4 Remove unnecessary comment from json_util.c 2012-07-08 20:32:12 -05:00
Mateusz Loskot
a6f39a3c0c Replaced #if HAVE_X with #ifdef HAVE_X as the former test is troublemaker with #define HAVE_X where #define HAVE_X 1|0 is meant. 2012-05-21 23:22:36 +01:00
Eric Haszlakiewicz
3fcffe1bb0 Add a json_object_to_json_string_ext() function to allow the formatting of output to be selected.
There are now three options: JSON_C_TO_STRING_SPACED, JSON_C_TO_STRING_PLAIN and JSON_C_TO_STRING_PRETTY.
This also add a json_object_to_file_ext() that takes the same flags.
Existing output of json_object_to_json_string() is unchanged, and uses JSON_C_TO_STRING_SPACED.
Thanks fo Grant Edwards for the initial patches.
2012-04-28 13:26:09 -05:00
John Arbash Meinel
6a231e4b41 Some updates to make the code compatible with VC 9 (2008)
VC 9 doesn't support late variable declarations, and doesn't have inttypes
so we need some direct definitions of a couple of more types.
2012-02-01 09:27:49 +01:00
Eric Haszlakiewicz
886c4fbebf Add a json_type_to_name() function which returns a string that describes the type. Useful for logging.
git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@67 327403b1-1117-474d-bef2-5cb71233fd97
2011-05-03 20:40:49 +00:00