Keith Derrick
c51b88d69a
Avoid potential overflow in json_object_get_double
sscanf is always a potential problem when converting numeric
values as it does not correctly handle over- and underflow
(or at least gives no indication that it has done so).
This change converts json_object_get_double() to use strtod()
according to CERT guidelines.
12 years ago
Eric Haszlakiewicz
06450206c4
Issue #59 : change the floating point output format to %.17g so values with more than 6 digits show up in the output.
12 years ago
Eric Haszlakiewicz
a23caf677c
Use sizeof instead of hard coded values when calling snprintf.
12 years ago
Eric Haszlakiewicz
51993c28c2
Added a json_object_new_double_s() convenience function to allow an exact string representation of a double to be specified when creating the object and use it in json_tokener_parse_ex() so a re-serialized object more exactly matches the input.
Add json_object_free_userdata() and json_object_userdata_to_json_string() too.
12 years ago
Eric Haszlakiewicz
ef43fe3571
Merge pull request #96 from rouault/remove_strdnup
Remove redefinition of strndup() which is no longer used in the codebase
12 years ago
Even Rouault
1a957c2edc
Remove redefinition of strndup() which is no longer used in the codebase
12 years ago
Taneli Mielikainen
c5523a17e8
fixing problem that isinf(-Inf) can be 1 or -1
12 years ago
Eric Haszlakiewicz
98a62a7652
Merge pull request #89 from ayanes/master
Support NaN and Infinity
12 years ago
Adrian Yanes
d086e2018c
Fixes for Infinity and NaN
Although JSON RFC does not support NaN or Infinity
as numeric values ECMA 262 section 9.8.1 defines
how to handle these cases as strings
12 years ago
Anatol Belski
ed819fb926
snprintf definition is needed here, too
12 years ago
Eric Haszlakiewicz
5b36a432c8
Merge branch 'remicollet-issue-float'
Conflicts:
json_util.c
12 years ago
Greg Hazel
cca74c6de6
add json_object_object_length
12 years ago
Alexander Klauer
2be921d883
Fixed json_object_object_add().
* Return value of json_object_object_add() changed from void to int.
Return value now indicates success or failure.
* Check whether allocations are successful.
* Do not exit program from within the library.
12 years ago
Abioy
7eaa849e9a
escape '\f' in json_escape_str
'\f' is a llegal char and should be escape in printbuf
12 years ago
Remi Collet
32d149c8f6
probably worth an option for this
12 years ago
Remi Collet
8c847968c7
Save space, drop unuseful trailing zeroes
12 years ago
Remi Collet
4014fe86d9
Simple fix to double encode
12 years ago
Eric Haszlakiewicz
4e4af93d66
Fix issue #53 - ensure explicit length string are still NUL terminated, and fix json_tokener_parse() to work properly with embedded unicode \u0000 values in strings.
Adjust test_null to check for this case.
See also http://bugs.debian.org/687269
12 years ago
Eric Haszlakiewicz
e36e562872
Reformat json_object_object_get() and json_object_object_get_ex().
13 years ago
Eric Haszlakiewicz
5450bed051
Fix json_object_object_get() so it returns NULL if the incoming json_object is NULL.
13 years ago
Eric Haszlakiewicz
5f4739e2eb
Change json_object_put to return 1 if the object passed was actually freed. (or 0 if only the reference count was decremented)
13 years ago
Eric Haszlakiewicz
38f421a2e7
Add a json_set_serializer() function to allow the string output of a json_object to be customized.
13 years ago
Eric Haszlakiewicz
6988f53fcb
Rewrite json_object_object_add to replace just the value if the key already exists so keys remain valid.
This is particularly useful when replacing values in a loop, since it allows
the key used by json_object_object_foreach to continue to be used.
13 years ago
Mateusz Loskot
271c53ebdd
Missing explicit casts from void* to specific pointers required. Added #define strcasecmp for Visual C++.
13 years ago
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.
13 years ago
Eric Haszlakiewicz
0cc1db6459
Change the format used for sprintbuf (but not scanf) to use %f instead of %lf because the "l" is unnecessary and some compilers behave differently with it present (e.g. MinGW).
Thanks for Mateusz Loskot for the fix.
13 years ago
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.
13 years ago
Eric Haszlakiewicz
4e000a65e6
Since we already use a local json_bool type, replace any stdbool.h usage with
that, since not all environments actually have a stdbool.h to use.
13 years ago
Keith Derrick
6917586acf
Add NULL-safe get object method
New json_object_object_get_ex() method protects itself against null pointers
and invalid objects being passed in.
13 years ago
Eric Haszlakiewicz
aef439a175
Adjust json_object_is_type and json_object_get_type so they return json_type_null for NULL objects.
13 years ago
Keith Derrick
37e7467476
Rename boolean type to json_bool
In building large systems, there are often clashes over the
preferred base type to use for bool/boolean. At least one
experience has been with a 3rd party proprietary library which
can not be changed. In that case, boolean was a synonym for
unsigned char and used widely in packed structures.
13 years ago
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.
13 years ago
Federico Culloca
7ec34c9b39
Added capitalized charaters to json_hex_chars
14 years ago
Frederik Deweerdt
c43871c866
Add new json_object_array_sort function
- uses libc's qsort to sort the arraylist
- add test in test1.c
14 years ago
Jehiah Czebotar
276123efe0
handle NULL passed to json_objct_object_get
Patch via Nikola Pajkovsky
git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@75 327403b1-1117-474d-bef2-5cb71233fd97
14 years ago
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
14 years ago
Eric Haszlakiewicz
e2e16011f0
Fix a bug in json_object_get_int() where calling it on a string type object would always return 0, instead of the actual numerical value of the string.
git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@66 327403b1-1117-474d-bef2-5cb71233fd97
14 years ago
Jehiah Czebotar
ac601b5b5f
update json_object_new_string_len, json_escape_str (internal). Writer handles \x00 correctly
Added parse_null test. This does not change anything with how the parser handles \u0000 or null characters
This commit is addapted from one by Adomas Paltanavičius <adomas@leanholding.com>
git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@63 327403b1-1117-474d-bef2-5cb71233fd97
14 years ago
ehaszla
252669cee6
Simplify things by storing integer values only as int64_t's internally, and
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
15 years ago
Michael Clark
c4dceae1c5
* Add int64 support. Two new functions json_object_net_int64 and
json_object_get_int64. Binary compatibility preserved.
Eric Haszlakiewicz, EHASZLA at transunion com
Rui Miguel Silva Seabra, rms at 1407 dot org
git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@56 327403b1-1117-474d-bef2-5cb71233fd97
15 years ago
Christopher Watford
c5cbf8214a
Disable REFCOUNT_DEBUG by default in json_object.c
git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@40 327403b1-1117-474d-bef2-5cb71233fd97
16 years ago
Michael Clark
6f70e44b7d
Fix json_object_get_boolean to return false for empty string
Spotted by Vitaly Kruglikov, Vitaly dot Kruglikov at palm dot com
git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@35 327403b1-1117-474d-bef2-5cb71233fd97
16 years ago
Michael Clark
aaec1ef3c5
* Don't use this as a variable, so we can compile with a C++ compiler
* Add casts from void* to type of assignment when using malloc
* Add #ifdef __cplusplus guards to all of the headers
* Add typedefs for json_object, json_tokener, array_list, printbuf, lh_table
Michael Clark, <michael@metaparadigm.com>
git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@33 327403b1-1117-474d-bef2-5cb71233fd97
16 years ago
Michael Clark
266a3fd301
* Don't use this as a variable, so we can compile with a C++ compiler
Michael Clark, <michael@metaparadigm.com>
git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@32 327403b1-1117-474d-bef2-5cb71233fd97
16 years ago
Michael Clark
22dee7cb59
* Null pointer dereference fix. Fix json_object_get_boolean strlen test
to not return TRUE for zero length string. Remove redundant includes.
Erik Hovland, erik at hovland dot org
git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@31 327403b1-1117-474d-bef2-5cb71233fd97
16 years ago
Michael Clark
e8de078806
* Fixed warning reported by adding -Wstrict-prototypes
-Wold-style-definition to the compilatin flags.
Dotan Barak, dotanba at gmail dot com
git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@30 327403b1-1117-474d-bef2-5cb71233fd97
16 years ago
Michael Clark
e6548a3dc2
fix typo in json_object.h
git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@28 327403b1-1117-474d-bef2-5cb71233fd97
16 years ago
Michael Clark
68cafad078
Add const correctness to public interfaces
Gerard Krol, g dot c dot krol at student dot tudelft dot nl
Update version number to 0.9
git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@27 327403b1-1117-474d-bef2-5cb71233fd97
16 years ago
Michael Clark
14862b1ef3
Patch allows for json-c compile with -Werror and not fail due to
-Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations
Geoffrey Young, geoff at modperlcookbook dot org
git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@20 327403b1-1117-474d-bef2-5cb71233fd97
18 years ago
Michael Clark
c8f4a6e7de
* Fix bug with use of capital E in numbers with exponents
Mateusz Loskot, mateusz at loskot dot net
* Add stddef.h include
git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@19 327403b1-1117-474d-bef2-5cb71233fd97
18 years ago