summaryrefslogtreecommitdiff
path: root/json_util.c
Commit message (Collapse)AuthorAgeFilesLines
* Apply same EINVAL handling to json_parse_uint64() as was done for ↵Eric Haszlakiewicz2022-10-301-1/+6
| | | | json_parse_int64(). Document that overflow/underflow for these functions is not an error, but sets errno=ERANGE.
* Issue #792 - set errno=EINVAL if parsing the string in json_parse_int64 ↵Eric Haszlakiewicz2022-10-261-1/+6
| | | | fails, to match the docs for json_object_get_int.
* Fix build with clang-15+Khem Raj2022-08-131-1/+1
| | | | | | | | | | | 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>
* Apply some of the fixes from PR #740, although by using size_t instead of ↵Eric Haszlakiewicz2022-07-311-9/+11
| | | | castings.
* json_object_from_fd_ex: fail if file is too largeTobias Stoeckmann2022-03-201-3/+10
| | | | | | | | 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.
* Fix error messagesTobias Stoeckmann2022-03-191-9/+9
| | | | Error messages did not reflect actual function names.
* json_type_to_name(): use correct printf() formatterEven Rouault2022-01-311-2/+2
| | | | | Was detected by Coverity Scan when analyzing GDAL's code base which has a copy of json-c
* Eliminate use of ctype.h and replace isdigit() and tolower() with ↵Eric Haszlakiewicz2020-08-021-1/+0
| | | | non-locale-sensitive approaches.
* Fix incremental parsing of invalid numbers with exponents, such as "0e+-" ↵Eric Haszlakiewicz2020-06-271-1/+2
| | | | | | and "12.3E12E12", while still allowing "0e+" in non-strict mode. Deprecate the json_parse_double() function from json_util.h
* fix json_parse_uint64() usage of errnoPierce Lopez2020-05-101-5/+3
| | | | | introduced in #542 fixes #601
* Re-do clang-format.Eric Haszlakiewicz2020-04-181-1/+0
|
* Make json_abort() internal to json_object.cEric Haszlakiewicz2020-04-181-6/+0
|
* Issue #568: fix the strtoll and strtoull handing so config.h ends up ↵Eric Haszlakiewicz2020-04-091-5/+0
| | | | creating defines for those only when needed, which should exclude mingw environments.
* clang-format the filesdota172020-04-031-71/+87
|
* add the disabling formatting coments and adjust the partial code manulydota172020-04-031-10/+13
|
* Fixes various Wreturn-type and Wimplicit-fallthrough errors on Mingw-w64Jehan2020-03-161-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a recent regression since commit 6359b798479d379a3202e02c6a938d9b40c0d856 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.
* modify the json_object, replace c_int64/c_uint64 with struct{union{int64, ↵dota172020-02-271-1/+0
| | | | uint64},...}
* add uint64 data to json-cdota172020-02-251-1/+20
|
* Define vars earlier to fix old Windows builds.Eric Haszlakiewicz2019-11-101-2/+3
|
* Add a json_object_from_fd_ex() function, to allow the max nesting depth to ↵Eric Haszlakiewicz2019-11-101-3/+25
| | | | be specified.
* Rename _set_last_err() to _json_c_set_last_err().Eric Haszlakiewicz2017-11-291-9/+9
|
* On VS 2013 and newer, actually use strtoll instead of redefining it to ↵Eric Haszlakiewicz2017-11-261-1/+4
| | | | _strtoi64.
* json_util: define `strtoll` as _strtoi64 for MSVCAlexandru Ardelean2017-11-071-0/+1
| | | | | | | | | Got the idea from this blog post: http://www.enchantedage.com/node/231 Simple & concise stuff :) Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
* Use strtoll to parse intsJason King2017-09-071-115/+8
|
* Issue #173: since some sscanf implementations return 0 for non-zero inputs, ↵Eric Haszlakiewicz2017-09-051-1/+3
| | | | directly check for "0" in the input.
* PR#331: for Visual Studio, use a snprintf/vsnprintf wrapper that ensures the ↵Eric Haszlakiewicz2017-08-251-6/+1
| | | | string is terminated.
* Fix parsing doubles for mingwtopilski2017-07-301-1/+3
|
* build: make `strerror()` override-ableAlexandru Ardelean2017-07-131-1/+2
| | | | | | | | | | | | | | | 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>
* Issue #161: add a json_object_to_fd() function.Eric Haszlakiewicz2017-06-181-30/+51
|
* Make _set_last_err() non-static so it can be used outside of json_util.cEric Haszlakiewicz2017-06-181-2/+1
|
* Issue #189: Eliminate use of MC_ERROR from json_util.c, and add a ↵Eric Haszlakiewicz2016-06-261-15/+27
| | | | | | 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
* Introduce json_object_from_fdMichael Heimpold2014-07-211-11/+26
| | | | | | | Also refactor json_object_from_file to use json_object_from_fd internally. Signed-off-by: Michael Heimpold <mhei@heimpold.de>
* Move the json_min() and json_max() macros to json_util.h and mark everything ↵Eric Haszlakiewicz2014-05-041-1/+0
| | | | | | else in bits.h deprecated. Eliminate all uses of bits.h within the json-c code.
* Update json_utilPascal Bach2013-08-131-2/+2
| | | | | filename should be passed as const char* to functions json_object_to_file and json_object_to_file
* Eliminate use of MC_ABORT in json-c code, and mark MC_ABORT/mc_abort deprecated.Eric Haszlakiewicz2013-06-291-2/+2
| | | | Also adjust an error message in json_util to make it unique. Fixes #87.
* Fix C89 compat needed by MSVCAnatol Belski2013-06-041-4/+5
|
* Merge branch 'remicollet-issue-float'Eric Haszlakiewicz2013-02-261-0/+5
|\ | | | | | | | | Conflicts: json_util.c
| * move locale change to be global for perfRemi Collet2012-12-131-21/+1
| |
| * float parsing must be locale independentRemi Collet2012-11-271-0/+25
| |
* | Add a runtime check to see if parse_int64 needs to workaround sscanf bugs. ↵Eric Haszlakiewicz2013-02-091-18/+63
| | | | | | | | If that workaround is not needed parsing is nearly twice as fast.
* | Enable -Werror and fix a number of minor warnings that existed.Eric Haszlakiewicz2013-02-091-2/+3
| |
* | rename _errnoGreg Hazel2013-01-031-5/+5
|/
* Initialize errno before calling sscanf in json_parse_int64() so parsing ↵Eric Haszlakiewicz2012-07-291-3/+6
| | | | valid numbers after parsing an out of range number works.
* Remove unnecessary comment from json_util.cEric Haszlakiewicz2012-07-081-1/+1
|
* Replaced #if HAVE_X with #ifdef HAVE_X as the former test is troublemaker ↵Mateusz Loskot2012-05-211-6/+12
| | | | with #define HAVE_X where #define HAVE_X 1|0 is meant.
* Add a json_object_to_json_string_ext() function to allow the formatting of ↵Eric Haszlakiewicz2012-04-281-5/+14
| | | | | | | | | 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.
* Some updates to make the code compatible with VC 9 (2008)John Arbash Meinel2012-02-011-3/+6
| | | | | 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.
* Add a json_type_to_name() function which returns a string that describes the ↵Eric Haszlakiewicz2011-05-031-0/+23
| | | | | | type. Useful for logging. git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@67 327403b1-1117-474d-bef2-5cb71233fd97
* Simplify things by storing integer values only as int64_t's internally, andehaszla2010-12-071-4/+18
| | | | | | | | | | omit the range check during parsing since we already have the checks when accessing the value. There is no longer a json_type_int64, only json_type_int. Fix some problems with parsing 0 and -0 values, and add a couple of tests. Fix some minor compile issues on HPUX environments. git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@60 327403b1-1117-474d-bef2-5cb71233fd97
* * Fix file descriptor leak if memory allocation fails in json_utilMichael Clark2010-10-131-2/+4
| | | | | | | | Zachary Blair, zack_blair at hotmail dot com git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@59 327403b1-1117-474d-bef2-5cb71233fd97