55 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
Tobias Stoeckmann
a7d85bfba9 Fix typos in comments
Spotted during code reviews.
2022-03-19 10:39:56 +01:00
Tobias Stoeckmann
cbc603b587 Adjusted URLs
Most of these sites support HTTPS (some forward to HTTPS when accessing
the HTTP versions). Use HTTPS directly if supported.

Some URLs led to 404 error pages. Adjusted the links to point to
new locations.

I did not adjust the Microsoft HTML Help Workshop link because it seems
that this software is not available anymore. Instead of removing the
link entirely I kept it there in case it helps someone to find the
software on archived websites.
2022-03-19 10:34:55 +01:00
Tobias Stoeckmann
543a8eb5f9 Fix typos
Mostly found with codespell and during code review.
2022-03-06 16:07:36 +01:00
Even Rouault
3bb54f97e7 Fix typos in code comments and ChangeLog 2022-02-25 00:14:47 +01:00
Robert Bielik
a66a6cc51b Fix for clang ub sanitizer 2021-11-11 09:51:18 +01:00
José Bollo
8bf3b45a29 Really use prefix JSON_C_OBJECT_ADD_*
This change introduces JSON_C_OBJECT_ADD_CONSTANT_KEY
as a replacement of JSON_C_OBJECT_KEY_IS_CONSTANT.

The description of json_object_object_add_ex tells to
look at the flags JSON_C_OBJECT_ADD_* but it is not
for JSON_C_OBJECT_KEY_IS_CONSTANT.

From the point of vue of a developper using json-c,
the function json_object_object_add_ex is mainly used,
not the hash facility, it seems more natural to provide
a regular naming of prefix JSON_C_OBJECT_ADD_CONSTANT_KEY.
2021-10-19 11:18:17 +02:00
Eric Haszlakiewicz
a59d5acfab Re-format after recent change to fix linkhash. 2020-05-10 03:58:27 +00:00
Eric Haszlakiewicz
519dfe1591 Issue #599: Fix the backwards check in lh_table_insert_w_hash() that was preventing adding more than 11 objects.
Add a test to check for this too.
2020-05-10 03:36:05 +00:00
Tobias Stoeckmann
d07b910149 Fix integer overflows.
The data structures linkhash and printbuf are limited to 2 GB in size
due to a signed integer being used to track their current size.

If too much data is added, then size variable can overflow, which is
an undefined behaviour in C programming language.

Assuming that a signed int overflow just leads to a negative value,
like it happens on many sytems (Linux i686/amd64 with gcc), then
printbuf is vulnerable to an out of boundary write on 64 bit systems.
2020-05-06 20:46:12 +02:00
Tobias Stoeckmann
77d935b7ae Prevent division by zero in linkhash.
If a linkhash with a size of zero is created, then modulo operations
are prone to division by zero operations.

Purely protective measure against bad usage.
2020-05-04 19:46:45 +02: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
Rubasri Kalidas
3003161eff Fix compiler warnings 2018-12-18 11:30:57 -06:00
Eric Haszlakiewicz
0992aac61f Remove the TRUE and FALSE defines. 2017-12-23 09:42:17 -05:00
Eric Haszlakiewicz
a19031411d Remove the previously deprecated lh_table_lookup() function, in favor of lh_table_lookup_ex(). 2017-12-10 00:27:01 -05:00
Eric Haszlakiewicz
f83cf244cd Remove the previously deprecated bits.h and the lh_abort() function. 2017-12-10 00:25:00 -05:00
Eric Haszlakiewicz
32f503f738 Issue #359: Don't duplicate lh_get_hash, just omit the "inline" for VS2010. 2017-09-06 23:42:30 -04:00
Haffon
e9f9f14f22 if compile with vs2015, enable the "static inline" declare. 2017-09-07 10:28:26 +08: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
Eric Haszlakiewicz
1d3e97f2ab Comment out the warning about racy random seed initialization in lh_char_hash(), if you're on a platform where it'll be triggered it just makes it a pain to build. 2017-07-09 15:13:02 -07:00
Pablo Sanabria
d3f813a14e Fixed linkhash.c for MinGW
Added #ifdef conditions for MinGW because this compiler doesn't define
gcc atomic builtins, so __sync_val_compare_and_swap was not found
neither any of any __GCC_HAVE_SYNC_COMPARE_AND_SWAP_* definition
2017-03-26 23:14:37 -03:00
marxin
014924ba89 Add FALLTHRU comment to handle GCC7 warnings. 2017-03-21 08:42:11 +01:00
Alex
175d934cff Fix compilation without C-99 option 2017-03-02 10:57:49 +02:00
Eswar Yaganti
5fb63a09f9 linkhash.c: optimised the table_free path 2016-06-25 22:50:36 +05:30
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
Eric Haszlakiewicz
f285c0a2e5 Issue #175: disable the fast-and-loose code in hashlittle() when running with AddressSanitizer. 2016-06-08 03:24:59 +00:00
Eric Haszlakiewicz
0539191d18 Check the __GCC_HAVE_SYNC_COMPARE_AND_SWAP_{2,4,8} defines to decide whether to use __sync_val_compare_and_swap(), as described at https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
Also, fix the types of the variables when building on Windows.
Also, should address issue #214.
2016-06-07 03:26:46 +00:00
Eric Haszlakiewicz
980cdd61be Merge commit '2be921d88376e78f84d79aafa6db2714da804e59' 2015-12-08 20:51:06 -06:00
Rainer Gerhards
36610fb697 fix regression from 2d549662be
That commit introduced read-only keys, but when the hash table
was resized, that attribute was not preserved. This resulted in
an invalid free at time of table destruction.
2015-11-19 11:05:15 +01:00
Eric Haszlakiewicz
12916e229c Merge pull request #196 from rgerhards/improve-performance
Performance improvements
2015-09-28 22:25:29 -04:00
Rainer Gerhards
1ae4b50bde remove unneeded data items from hashtable code
These items were used for statistics tracking, but no code at all
exists to consume them. By removing them we save

a) space
   because they counters required space, and did so in each and every
   json object

b) performance
   because calloc() needs to write less data and the counters are
   no longer maintained; cache performance can be better, load
   on OS main memory is lighter

We could conditionally enable/disable these counters, but I have not
done this they were really nowhere used and it looked more like a
left-over from the import of hashtable code.
2015-09-23 12:40:57 +02:00
Rainer Gerhards
8f8d03df46 add perllike hash function for strings
This also adds a new API json_global_set_string_hash() which permits
to select the hash function. The default one is the only one that was
previously present. So there are no changes to existing apps, and the
new hash function needs to be explicitely be opted in. Especially for
smaller strings, the perllike functions seems to be around twice as
fast as the other one, with similarly good results in value distribution.
2015-09-23 12:23:09 +02:00
Rainer Gerhards
2d549662be add json_object_object_add_ex() API
This provides more control over some detail aspects, many
of which are performance related.
2015-09-23 09:43:00 +02:00
Rainer Gerhards
d8e44dc685 reduce duplicate hash computation in json_object_object_add()
This can be a very considerable performance saver.
2015-09-22 19:07:30 +02:00
Eric Haszlakiewicz
cd8bd7f617 Tell the compiler we're intentionally ignoring the return value from __sync_val_compare_and_swap(). 2015-05-26 19:02:19 -07:00
James Myatt
18b3c49296 Use more appropriate casts 2015-03-04 10:45:37 +00:00
James Myatt
0137103f4b Include config.h in linkhash so that HAVE_ENDIAN_H is defined (if available) 2015-03-04 10:45:33 +00:00
Eric Haszlakiewicz
7e3a6c6b9d Merge pull request #163 from sixlettervariables/fix-win32-build-problems
Fix Win32 build problems
2015-03-03 22:35:36 -05:00
Christopher Watford
0609a5729c Fixes #160 'missing header file on windows' 2014-12-05 10:22:36 -05:00
Michael Vetter
fcf5ad1bd6 Remove trailing whitespace 2014-08-26 14:48:59 +02:00
Michael Clark
64e36901a0 Patch to address the following issues:
* CVE-2013-6371: hash collision denial of service
* CVE-2013-6370: buffer overflow if size_t is larger than int
2014-04-09 13:48:21 +08: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
cca74c6de6 add json_object_object_length 2013-01-11 01:36:55 -08:00
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.
2013-01-08 14:24:21 +01:00
Keith Derrick
4a2cd966f5 Add NULL-safe lookup function
New lh_table_lookup_ex() method protects itself against null pointers
and invalid objects being passed in.
2012-04-12 11:47:56 -07:00
Eric Haszlakiewicz
64c0ca3690 Define a LH_LOAD_FACTOR constant and note the range that it can be set to.
Change the resize check from "count > size" to "count >= size" to avoid a
potential infinite loop with high load factors and a full hash table.
2012-03-31 17:33:58 -05:00
Michael Clark
f5dd43a9d1 * Fix subtle bug in linkhash where lookup could hang after all slots
were filled then successively freed.
    Spotted by Jean-Marc Naud, j dash m at newtraxtech dot com


git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@54 327403b1-1117-474d-bef2-5cb71233fd97
2009-08-27 06:40:00 +00:00
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
2009-02-25 02:31:32 +00:00
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
2009-02-25 01:51:40 +00:00