From 8c4a9414753ca2825b3cb9ae4315520200d50491 Mon Sep 17 00:00:00 2001 From: Eric Haszlakiewicz Date: Sat, 9 Dec 2017 14:59:05 -0500 Subject: [PATCH 01/28] Tweak the release checklist slightly to fix problems noticed during this past release process. --- RELEASE_CHECKLIST.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/RELEASE_CHECKLIST.txt b/RELEASE_CHECKLIST.txt index 642cefb..c18713f 100644 --- a/RELEASE_CHECKLIST.txt +++ b/RELEASE_CHECKLIST.txt @@ -1,7 +1,7 @@ Release checklist: -release=0.12 +release=0.14 git clone https://github.com/json-c/json-c json-c-${release} cd json-c-${release} @@ -22,6 +22,7 @@ Update the version in json_c_version.h Update the version in Doxyfile Update the version in configure.ac Update the version in CMakeLists.txt +Update the version in config.h.win32 Use ${release}. Update the libjson_la_LDFLAGS line in Makefile.am to the new version. @@ -37,7 +38,7 @@ Generate the configure script and other files: git add -f Makefile.in aclocal.m4 config.guess config.h.in \ config.sub configure depcomp install-sh \ ltmain.sh missing tests/Makefile.in \ - INSTALL + INSTALL compile test-driver # check for anything else to be added: git status --ignored @@ -90,9 +91,10 @@ Update the version in json_c_version.h Update the version in Doxyfile Update the version in configure.ac Update the version in CMakeLists.txt +Update the version in config.h.win32 Use ${release}.99 to indicate a version "newer" than anything on the branch. -Leave the libjson_la_LDFLAGS line in Makefile.am alone. +Update the libjson_la_LDFLAGS line in Makefile.am to match the release branch. For more details see: http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html From 0631c37c7f51231787b0d5611c7712856820e95e Mon Sep 17 00:00:00 2001 From: Eric Haszlakiewicz Date: Sat, 9 Dec 2017 14:59:48 -0500 Subject: [PATCH 02/28] Update the master branch to version 0.13.99 --- CMakeLists.txt | 2 +- ChangeLog | 6 ++++++ Doxyfile | 2 +- Makefile.am | 2 +- config.h.win32 | 6 +++--- configure.ac | 2 +- json_c_version.h | 6 +++--- 7 files changed, 16 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 15492df..36b61a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8.7) cmake_policy(SET CMP0048 NEW) -project(json-c VERSION 0.12.99) +project(json-c VERSION 0.13.99) include(CheckSymbolExists) diff --git a/ChangeLog b/ChangeLog index e079337..75357c1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,10 @@ +Next version, 0.14 +================== + +Nothing yet. + + 0.13 (up to commit 5dae561, 2017/11/29) ================================= diff --git a/Doxyfile b/Doxyfile index 31e9025..a74032d 100644 --- a/Doxyfile +++ b/Doxyfile @@ -38,7 +38,7 @@ PROJECT_NAME = json-c # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 0.12.99 +PROJECT_NUMBER = 0.13.99 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/Makefile.am b/Makefile.am index 435ed7e..7e42185 100644 --- a/Makefile.am +++ b/Makefile.am @@ -42,7 +42,7 @@ noinst_HEADERS=\ random_seed.h \ strerror_override.h -libjson_c_la_LDFLAGS = -version-info 3:0:0 -no-undefined @JSON_BSYMBOLIC_LDFLAGS@ +libjson_c_la_LDFLAGS = -version-info 3:1:0 -no-undefined @JSON_BSYMBOLIC_LDFLAGS@ libjson_c_la_SOURCES = \ arraylist.c \ diff --git a/config.h.win32 b/config.h.win32 index 3e8b218..0e14c7a 100644 --- a/config.h.win32 +++ b/config.h.win32 @@ -175,7 +175,7 @@ #define PACKAGE_NAME "JSON C Library" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "JSON C Library 0.12.99" +#define PACKAGE_STRING "JSON C Library 0.13.99" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "json-c" @@ -184,13 +184,13 @@ #define PACKAGE_URL "https://github.com/json-c/json-c" /* Define to the version of this package. */ -#define PACKAGE_VERSION "0.12.99" +#define PACKAGE_VERSION "0.13.99" /* Define to 1 if you have the ANSI C header files. */ #define STDC_HEADERS 1 /* Version number of package */ -#define VERSION "0.12.99" +#define VERSION "0.13.99" /* Define to empty if `const' does not conform to ANSI C. */ /* #undef const */ diff --git a/configure.ac b/configure.ac index d29a387..ef556eb 100644 --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,7 @@ AC_PREREQ(2.64) # Process this file with autoconf to produce a configure script. -AC_INIT([json-c], 0.12.99, [json-c@googlegroups.com]) +AC_INIT([json-c], 0.13.99, [json-c@googlegroups.com]) AM_INIT_AUTOMAKE diff --git a/json_c_version.h b/json_c_version.h index 442174f..a623f38 100644 --- a/json_c_version.h +++ b/json_c_version.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012 Eric Haszlakiewicz + * Copyright (c) 2012,2017 Eric Haszlakiewicz * * This library is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See COPYING for details. @@ -13,12 +13,12 @@ #define _json_c_version_h_ #define JSON_C_MAJOR_VERSION 0 -#define JSON_C_MINOR_VERSION 12 +#define JSON_C_MINOR_VERSION 13 #define JSON_C_MICRO_VERSION 99 #define JSON_C_VERSION_NUM ((JSON_C_MAJOR_VERSION << 16) | \ (JSON_C_MINOR_VERSION << 8) | \ JSON_C_MICRO_VERSION) -#define JSON_C_VERSION "0.12.99" +#define JSON_C_VERSION "0.13.99" /** * @see JSON_C_VERSION From 963e707ca4d6586e91ce3d48105ebcd69dbbe872 Mon Sep 17 00:00:00 2001 From: Eric Haszlakiewicz Date: Sat, 9 Dec 2017 15:12:08 -0500 Subject: [PATCH 03/28] Drop mention of README-WIN32.html in the release checklist. --- RELEASE_CHECKLIST.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/RELEASE_CHECKLIST.txt b/RELEASE_CHECKLIST.txt index c18713f..12f5d63 100644 --- a/RELEASE_CHECKLIST.txt +++ b/RELEASE_CHECKLIST.txt @@ -110,7 +110,6 @@ git clone -b gh-pages https://github.com/json-c/json-c json-c-pages cd json-c-pages mkdir json-c-${release} cp -R ../json-c-${release}/doc json-c-${release}/. -cp ../json-c-${release}/README-WIN32.html json-c-${release}/. git add json-c-${release} git commit From f83cf244cd27c7ef06f1852d1f3280fedfb19ae3 Mon Sep 17 00:00:00 2001 From: Eric Haszlakiewicz Date: Sun, 10 Dec 2017 00:25:00 -0500 Subject: [PATCH 04/28] Remove the previously deprecated bits.h and the lh_abort() function. --- ChangeLog | 5 ++++- Makefile.am | 1 - bits.h | 36 ------------------------------------ linkhash.c | 9 --------- linkhash.h | 15 --------------- 5 files changed, 4 insertions(+), 62 deletions(-) delete mode 100644 bits.h diff --git a/ChangeLog b/ChangeLog index 75357c1..c7ca51b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,7 +2,10 @@ Next version, 0.14 ================== -Nothing yet. +Deprecated and removed features: +-------------------------------- +* bits.h has been removed +* lh_abort() has been removed 0.13 (up to commit 5dae561, 2017/11/29) diff --git a/Makefile.am b/Makefile.am index 7e42185..5ad354a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -18,7 +18,6 @@ pkgconfig_DATA = json-c.pc libjson_cincludedir = $(includedir)/json-c libjson_cinclude_HEADERS = \ arraylist.h \ - bits.h \ debug.h \ json.h \ json_c_version.h \ diff --git a/bits.h b/bits.h deleted file mode 100644 index 14c1c13..0000000 --- a/bits.h +++ /dev/null @@ -1,36 +0,0 @@ -/** - * @file - * @brief Do not use, only contains deprecated defines. - * @deprecated Use json_util.h instead. - * - * $Id: bits.h,v 1.10 2006/01/30 23:07:57 mclark Exp $ - * - * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. - * Michael Clark - * - * This library is free software; you can redistribute it and/or modify - * it under the terms of the MIT license. See COPYING for details. - * - */ - -#ifndef _bits_h_ -#define _bits_h_ - -/** - * @deprecated - */ -#define hexdigit(x) (((x) <= '9') ? (x) - '0' : ((x) & 7) + 9) -/** - * @deprecated - */ -#define error_ptr(error) ((void*)error) -/** - * @deprecated - */ -#define error_description(error) (json_tokener_get_error(error)) -/** - * @deprecated - */ -#define is_error(ptr) (ptr == NULL) - -#endif diff --git a/linkhash.c b/linkhash.c index 5497061..73691cd 100644 --- a/linkhash.c +++ b/linkhash.c @@ -52,15 +52,6 @@ json_global_set_string_hash(const int h) return 0; } -void lh_abort(const char *msg, ...) -{ - va_list ap; - va_start(ap, msg); - vprintf(msg, ap); - va_end(ap); - exit(1); -} - static unsigned long lh_ptr_hash(const void *k) { /* CAW: refactored to be 64bit nice */ diff --git a/linkhash.h b/linkhash.h index 9c2f5c1..0f0e398 100644 --- a/linkhash.h +++ b/linkhash.h @@ -318,21 +318,6 @@ extern int lh_table_delete(struct lh_table *t, const void *k); extern int lh_table_length(struct lh_table *t); -/** - * Prints a message to stdout, - * then exits the program with an exit code of 1. - * - * @param msg Message format string, like for printf. - * @param ... Format args. - * - * @deprecated Since it is not a good idea to exit the entire program - * because of an internal library failure, json-c will no longer - * use this function internally. - * However, because its interface is public, it will remain part of - * the API on the off chance of legacy software using it externally. - */ -THIS_FUNCTION_IS_DEPRECATED(void lh_abort(const char *msg, ...)); - /** * Resizes the specified table. * From a19031411ddcc3d9a0cc79bef8ab17efb33ea8fd Mon Sep 17 00:00:00 2001 From: Eric Haszlakiewicz Date: Sun, 10 Dec 2017 00:27:01 -0500 Subject: [PATCH 05/28] Remove the previously deprecated lh_table_lookup() function, in favor of lh_table_lookup_ex(). --- ChangeLog | 1 + linkhash.c | 7 ------- linkhash.h | 10 ---------- 3 files changed, 1 insertion(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index c7ca51b..f5fee96 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ Deprecated and removed features: -------------------------------- * bits.h has been removed * lh_abort() has been removed +* lh_table_lookup() has been removed, use lh_table_lookup_ex() instead. 0.13 (up to commit 5dae561, 2017/11/29) diff --git a/linkhash.c b/linkhash.c index 73691cd..7dddc36 100644 --- a/linkhash.c +++ b/linkhash.c @@ -621,13 +621,6 @@ struct lh_entry* lh_table_lookup_entry(struct lh_table *t, const void *k) return lh_table_lookup_entry_w_hash(t, k, lh_get_hash(t, k)); } -const void* lh_table_lookup(struct lh_table *t, const void *k) -{ - void *result; - lh_table_lookup_ex(t, k, &result); - return result; -} - json_bool lh_table_lookup_ex(struct lh_table* t, const void* k, void **v) { struct lh_entry *e = lh_table_lookup_entry(t, k); diff --git a/linkhash.h b/linkhash.h index 0f0e398..89ef3da 100644 --- a/linkhash.h +++ b/linkhash.h @@ -271,16 +271,6 @@ extern struct lh_entry* lh_table_lookup_entry(struct lh_table *t, const void *k) */ extern struct lh_entry* lh_table_lookup_entry_w_hash(struct lh_table *t, const void *k, const unsigned long h); -/** - * Lookup a record into the table. - * - * @param t the table to lookup - * @param k a pointer to the key to lookup - * @return a pointer to the found value or NULL if it does not exist. - * @deprecated Use lh_table_lookup_ex() instead. - */ -THIS_FUNCTION_IS_DEPRECATED(extern const void* lh_table_lookup(struct lh_table *t, const void *k)); - /** * Lookup a record in the table. * From 89747ac75892b58c6c8c4de36dfbcec0f547db95 Mon Sep 17 00:00:00 2001 From: Alexander Dahl Date: Mon, 11 Dec 2017 09:46:28 +0100 Subject: [PATCH 06/28] doc: Use other doxygen feature to specify mainpage Previously a special tag was added to README.md to make this the main page in Doxygen generated docs. When viewing the README on the GitHub page this tag was not hidden. After upgrading to Doxygen 1.8.8 (and above) in changeset 219025727dd7d981cf2fea7f2095570924e7bae7 a new Doxygen feature can be used to specify the main page: Since release 1.8.3 Doxygen has a special option to set a markdown file as main page. When using this option we can drop the tag, making the README rendered by GitHub nice to look at. Fixes: ae66b243690871f2daea5ae4b2a4669081d7c556 --- Doxyfile | 5 ++--- README.md | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Doxyfile b/Doxyfile index a74032d..8a5523f 100644 --- a/Doxyfile +++ b/Doxyfile @@ -753,8 +753,7 @@ WARN_LOGFILE = # spaces. # Note: If this tag is empty the current directory is searched. -INPUT = README.md \ - . +INPUT = # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses @@ -891,7 +890,7 @@ FILTER_SOURCE_PATTERNS = # (index.html). This can be useful if you have a project on for instance GitHub # and want to reuse the introduction page also for the doxygen output. -USE_MDFILE_AS_MAINPAGE = +USE_MDFILE_AS_MAINPAGE = README.md #--------------------------------------------------------------------------- # Configuration options related to source browsing diff --git a/README.md b/README.md index 1441e93..3e2f065 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -`json-c` {#mainpage} +`json-c` ======== 1. [Overview and Build Status](#overview) From c123a1c21b944b3391fe022263ebfcdc15e5c5d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Esser?= Date: Mon, 11 Dec 2017 12:55:40 +0100 Subject: [PATCH 07/28] json_object: Add size_t json_object_sizeof() --- json_object.c | 5 +++++ json_object.h | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/json_object.c b/json_object.c index 9daa6fd..f12d8f0 100644 --- a/json_object.c +++ b/json_object.c @@ -509,6 +509,11 @@ int json_object_object_length(const struct json_object *jso) return lh_table_length(jso->o.c_object); } +size_t json_object_sizeof(void) +{ + return sizeof(struct json_object); +} + struct json_object* json_object_object_get(const struct json_object* jso, const char *key) { diff --git a/json_object.h b/json_object.h index 283eb95..6a2751d 100644 --- a/json_object.h +++ b/json_object.h @@ -392,6 +392,11 @@ JSON_EXPORT struct lh_table* json_object_get_object(const struct json_object *ob */ JSON_EXPORT int json_object_object_length(const struct json_object* obj); +/** Get the sizeof (struct json_object). + * @returns a size_t with the sizeof (struct json_object) + */ +JSON_EXPORT size_t json_object_sizeof(void); + /** Add an object field to a json_object of type json_type_object * * The reference count will *not* be incremented. This is to make adding From 5b6d62259afbc1709d4437b8c488de429079cae0 Mon Sep 17 00:00:00 2001 From: Eric Haszlakiewicz Date: Tue, 12 Dec 2017 18:26:51 -0500 Subject: [PATCH 08/28] Apply gcc's "const" attribute to the json_c_object_sizeof() function as an optimizer hint. Also, rename that function from json_object_sizeof(). --- json_object.c | 2 +- json_object.h | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/json_object.c b/json_object.c index f12d8f0..042477a 100644 --- a/json_object.c +++ b/json_object.c @@ -509,7 +509,7 @@ int json_object_object_length(const struct json_object *jso) return lh_table_length(jso->o.c_object); } -size_t json_object_sizeof(void) +size_t json_c_object_sizeof(void) { return sizeof(struct json_object); } diff --git a/json_object.h b/json_object.h index 6a2751d..758efa6 100644 --- a/json_object.h +++ b/json_object.h @@ -27,6 +27,12 @@ #define THIS_FUNCTION_IS_DEPRECATED(func) func #endif +#ifdef __GNUC__ +#define JSON_C_CONST_FUNCTION(func) func __attribute__((const)) +#else +#define CONST_FUNCTION(func) func +#endif + #if defined(_MSC_VER) #define JSON_EXPORT __declspec(dllexport) #else @@ -395,7 +401,7 @@ JSON_EXPORT int json_object_object_length(const struct json_object* obj); /** Get the sizeof (struct json_object). * @returns a size_t with the sizeof (struct json_object) */ -JSON_EXPORT size_t json_object_sizeof(void); +JSON_C_CONST_FUNCTION(JSON_EXPORT size_t json_c_object_sizeof(void)); /** Add an object field to a json_object of type json_type_object * From 87556afe2a062c28bccd910ec5bc22b9988726e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Esser?= Date: Sun, 10 Dec 2017 16:29:41 +0100 Subject: [PATCH 09/28] Makefile: Add ACLOCAL_AMFLAGS This is recommended by the libtool manual. --- Makefile.am | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile.am b/Makefile.am index 5ad354a..a0a43fc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,3 +1,5 @@ +ACLOCAL_AMFLAGS = -I autoconf-archive/m4 + EXTRA_DIST = README.md README.html EXTRA_DIST += config.h.win32 EXTRA_DIST += Doxyfile From 84dcc01da193e870bb756254fff7cb34efde0459 Mon Sep 17 00:00:00 2001 From: Rikard Falkeborn Date: Wed, 13 Dec 2017 22:24:50 +0100 Subject: [PATCH 10/28] Fix non-GNUC define for JSON_C_CONST_FUNCTION --- json_object.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json_object.h b/json_object.h index 758efa6..4b7a246 100644 --- a/json_object.h +++ b/json_object.h @@ -30,7 +30,7 @@ #ifdef __GNUC__ #define JSON_C_CONST_FUNCTION(func) func __attribute__((const)) #else -#define CONST_FUNCTION(func) func +#define JSON_C_CONST_FUNCTION(func) func #endif #if defined(_MSC_VER) From 9aca3b6a087a396a81d7e26f4557eb97fecc1386 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Esser?= Date: Wed, 13 Dec 2017 19:22:52 +0100 Subject: [PATCH 11/28] json_object: Avoid invalid free (and thus a segfault) when ref_count gets < 0 --- json_object.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/json_object.c b/json_object.c index 042477a..7c7438d 100644 --- a/json_object.c +++ b/json_object.c @@ -182,6 +182,11 @@ int json_object_put(struct json_object *jso) { if(!jso) return 0; + /* Avoid invalid free and crash explicitly instead of (silently) + * segfaulting. + */ + assert(jso->_ref_count > 0); + #if defined(HAVE_ATOMIC_BUILTINS) && defined(ENABLE_THREADING) /* Note: this only allow the refcount to remain correct * when multiple threads are adjusting it. It is still an error From c233f5c05e92909a764973524a03471bfad78f09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Esser?= Date: Sat, 16 Dec 2017 17:09:39 +0100 Subject: [PATCH 12/28] json_object_private: Use unsigned 32-bit integer type for refcount --- json_object.c | 3 +++ json_object_private.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/json_object.c b/json_object.c index 7c7438d..da96f4c 100644 --- a/json_object.c +++ b/json_object.c @@ -169,6 +169,9 @@ extern struct json_object* json_object_get(struct json_object *jso) { if (!jso) return jso; + // Don't overflow the refcounter. + assert(jso->_ref_count < UINT_FAST32_MAX); + #if defined(HAVE_ATOMIC_BUILTINS) && defined(ENABLE_THREADING) __sync_add_and_fetch(&jso->_ref_count, 1); #else diff --git a/json_object_private.h b/json_object_private.h index 53be70d..51134b6 100644 --- a/json_object_private.h +++ b/json_object_private.h @@ -29,7 +29,7 @@ struct json_object enum json_type o_type; json_object_private_delete_fn *_delete; json_object_to_json_string_fn *_to_json_string; - int _ref_count; + uint_fast32_t _ref_count; struct printbuf *_pb; union data { json_bool c_boolean; From 0992aac61f8b087efd7094e9ac2b84fa9c040fcd Mon Sep 17 00:00:00 2001 From: Eric Haszlakiewicz Date: Sat, 23 Dec 2017 09:42:17 -0500 Subject: [PATCH 13/28] Remove the TRUE and FALSE defines. --- ChangeLog | 1 + json_object.c | 8 ++++---- json_object.h | 16 +++++----------- linkhash.c | 4 ++-- tests/test_set_value.c | 12 ++++++------ 5 files changed, 18 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index f5fee96..5dd29ab 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,7 @@ Deprecated and removed features: * bits.h has been removed * lh_abort() has been removed * lh_table_lookup() has been removed, use lh_table_lookup_ex() instead. +* Remove TRUE and FALSE defines, use 1 and 0 instead. 0.13 (up to commit 5dae561, 2017/11/29) diff --git a/json_object.c b/json_object.c index da96f4c..4d6e2e7 100644 --- a/json_object.c +++ b/json_object.c @@ -537,7 +537,7 @@ json_bool json_object_object_get_ex(const struct json_object* jso, const char *k *value = NULL; if (NULL == jso) - return FALSE; + return 0; switch(jso->o_type) { @@ -547,7 +547,7 @@ json_bool json_object_object_get_ex(const struct json_object* jso, const char *k default: if (value != NULL) *value = NULL; - return FALSE; + return 0; } } @@ -583,7 +583,7 @@ struct json_object* json_object_new_boolean(json_bool b) json_bool json_object_get_boolean(const struct json_object *jso) { if (!jso) - return FALSE; + return 0; switch(jso->o_type) { case json_type_boolean: @@ -595,7 +595,7 @@ json_bool json_object_get_boolean(const struct json_object *jso) case json_type_string: return (jso->o.c_string.len != 0); default: - return FALSE; + return 0; } } diff --git a/json_object.h b/json_object.h index 4b7a246..db63d22 100644 --- a/json_object.h +++ b/json_object.h @@ -118,12 +118,6 @@ extern "C" { */ #define JSON_C_OBJECT_KEY_IS_CONSTANT (1<<2) -#undef FALSE -#define FALSE ((json_bool)0) - -#undef TRUE -#define TRUE ((json_bool)1) - /** * Set the global value of an option, which will apply to all * current and future threads that have not set a thread-local value. @@ -654,7 +648,7 @@ JSON_EXPORT int json_object_array_del_idx(struct json_object *obj, size_t idx, s /* json_bool type methods */ /** Create a new empty json_object of type json_type_boolean - * @param b a json_bool TRUE or FALSE (1 or 0) + * @param b a json_bool 1 or 0 * @returns a json_object of type json_type_boolean */ JSON_EXPORT struct json_object* json_object_new_boolean(json_bool b); @@ -662,10 +656,10 @@ JSON_EXPORT struct json_object* json_object_new_boolean(json_bool b); /** Get the json_bool value of a json_object * * The type is coerced to a json_bool if the passed object is not a json_bool. - * integer and double objects will return FALSE if there value is zero - * or TRUE otherwise. If the passed object is a string it will return - * TRUE if it has a non zero length. If any other object type is passed - * TRUE will be returned if the object is not NULL. + * integer and double objects will return 0 if there value is zero + * or 1 otherwise. If the passed object is a string it will return + * 1 if it has a non zero length. If any other object type is passed + * 1 will be returned if the object is not NULL. * * @param obj the json_object instance * @returns a json_bool diff --git a/linkhash.c b/linkhash.c index 7dddc36..b1223c4 100644 --- a/linkhash.c +++ b/linkhash.c @@ -626,10 +626,10 @@ json_bool lh_table_lookup_ex(struct lh_table* t, const void* k, void **v) struct lh_entry *e = lh_table_lookup_entry(t, k); if (e != NULL) { if (v != NULL) *v = lh_entry_v(e); - return TRUE; /* key found */ + return 1; /* key found */ } if (v != NULL) *v = NULL; - return FALSE; /* key not found */ + return 0; /* key not found */ } int lh_table_delete_entry(struct lh_table *t, struct lh_entry *e) diff --git a/tests/test_set_value.c b/tests/test_set_value.c index 4c0a54a..1f80b0e 100644 --- a/tests/test_set_value.c +++ b/tests/test_set_value.c @@ -15,12 +15,12 @@ int main(int argc, char **argv) assert (json_object_get_int64(tmp)==321321321); json_object_put(tmp); printf("INT64 PASSED\n"); - tmp=json_object_new_boolean(TRUE); - assert (json_object_get_boolean(tmp)==TRUE); - json_object_set_boolean(tmp,FALSE); - assert (json_object_get_boolean(tmp)==FALSE); - json_object_set_boolean(tmp,TRUE); - assert (json_object_get_boolean(tmp)==TRUE); + tmp=json_object_new_boolean(1); + assert (json_object_get_boolean(tmp)==1); + json_object_set_boolean(tmp,0); + assert (json_object_get_boolean(tmp)==0); + json_object_set_boolean(tmp,1); + assert (json_object_get_boolean(tmp)==1); json_object_put(tmp); printf("BOOL PASSED\n"); tmp=json_object_new_double(12.34); From d5da847f51abae8eb45fd5d25b109823d977614b Mon Sep 17 00:00:00 2001 From: Eric Haszlakiewicz Date: Sun, 24 Dec 2017 13:45:52 -0500 Subject: [PATCH 14/28] PR#394: don't always append the ".0" if the double value rounds to zero because some custom formats *will* include it (e.g. %.2f). Also try to accomodate formats to explicitly exclude the decimal (e.g. %.0f). --- json_object.c | 74 ++++++++++++++++----------- tests/test_double_serializer.c | 20 ++++++++ tests/test_double_serializer.expected | 4 ++ 3 files changed, 69 insertions(+), 29 deletions(-) diff --git a/json_object.c b/json_object.c index 4d6e2e7..52e8b76 100644 --- a/json_object.c +++ b/json_object.c @@ -15,6 +15,7 @@ #include "strerror_override.h" #include +#include #include #include #include @@ -790,7 +791,6 @@ static int json_object_double_to_json_string_format(struct json_object* jso, { char buf[128], *p, *q; int size; - double dummy; /* needed for modf() */ /* Although JSON RFC does not support NaN or Infinity as numeric values ECMA 262 section 9.8.1 defines @@ -810,44 +810,60 @@ static int json_object_double_to_json_string_format(struct json_object* jso, { const char *std_format = "%.17g"; -#if defined(HAVE___THREAD) - if (tls_serialization_float_format) - std_format = tls_serialization_float_format; - else -#endif - if (global_serialization_float_format) - std_format = global_serialization_float_format; if (!format) - format = std_format; - size = snprintf(buf, sizeof(buf), format, jso->o.c_double); - if (modf(jso->o.c_double, &dummy) == 0 && size >= 0 && size < (int)sizeof(buf) - 2) { - // Ensure it looks like a float, even if snprintf didn't. +#if defined(HAVE___THREAD) + if (tls_serialization_float_format) + format = tls_serialization_float_format; + else +#endif + if (global_serialization_float_format) + format = global_serialization_float_format; + else + format = std_format; + } + size = snprintf(buf, sizeof(buf), format, jso->o.c_double); + + if (size < 0) + return -1; + + p = strchr(buf, ','); + if (p) + *p = '.'; + else + p = strchr(buf, '.'); + + int format_drops_decimals = 0; + if (format == std_format || strstr(format, ".0f") == NULL) + format_drops_decimals = 1; + + if (size < (int)sizeof(buf) - 2 && + isdigit((int)buf[0]) && /* Looks like *some* kind of number */ + !p && /* Has no decimal point */ + strchr(buf, 'e') == NULL && /* Not scientific notation */ + format_drops_decimals) + { + // Ensure it looks like a float, even if snprintf didn't, + // unless a custom format is set to omit the decimal. strcat(buf, ".0"); size += 2; } + if (p && (flags & JSON_C_TO_STRING_NOZERO)) + { + /* last useful digit, always keep 1 zero */ + p++; + for (q=p ; *q ; q++) { + if (*q!='0') p=q; + } + /* drop trailing zeroes */ + *(++p) = 0; + size = p-buf; + } } // although unlikely, snprintf can fail if (size < 0) return -1; - p = strchr(buf, ','); - if (p) - *p = '.'; - else - p = strchr(buf, '.'); - if (p && (flags & JSON_C_TO_STRING_NOZERO)) - { - /* last useful digit, always keep 1 zero */ - p++; - for (q=p ; *q ; q++) { - if (*q!='0') p=q; - } - /* drop trailing zeroes */ - *(++p) = 0; - size = p-buf; - } - if (size >= (int)sizeof(buf)) // The standard formats are guaranteed not to overrun the buffer, // but if a custom one happens to do so, just silently truncate. diff --git a/tests/test_double_serializer.c b/tests/test_double_serializer.c index c7b229e..0f7a60e 100644 --- a/tests/test_double_serializer.c +++ b/tests/test_double_serializer.c @@ -54,4 +54,24 @@ int main() printf("obj.to_string(back to default format)=%s\n", json_object_to_json_string(obj)); json_object_put(obj); + + obj = json_object_new_double(12.0); + printf("obj(12.0).to_string(default format)=%s\n", json_object_to_json_string(obj)); + if (json_c_set_serialization_double_format("%.0f", JSON_C_OPTION_GLOBAL) < 0) + printf("ERROR: json_c_set_serialization_double_format() failed"); + printf("obj(12.0).to_string(%%.0f)=%s\n", json_object_to_json_string(obj)); + + if (json_c_set_serialization_double_format("%.0g", JSON_C_OPTION_GLOBAL) < 0) + printf("ERROR: json_c_set_serialization_double_format() failed"); + printf("obj(12.0).to_string(%%.0g)=%s\n", json_object_to_json_string(obj)); + + if (json_c_set_serialization_double_format("%.2g", JSON_C_OPTION_GLOBAL) < 0) + printf("ERROR: json_c_set_serialization_double_format() failed"); + printf("obj(12.0).to_string(%%.1g)=%s\n", json_object_to_json_string(obj)); + + // Reset to default to free memory + if (json_c_set_serialization_double_format(NULL, JSON_C_OPTION_GLOBAL) < 0) + printf("ERROR: json_c_set_serialization_double_format() failed"); + + json_object_put(obj); } diff --git a/tests/test_double_serializer.expected b/tests/test_double_serializer.expected index cd5f02b..98eea1e 100644 --- a/tests/test_double_serializer.expected +++ b/tests/test_double_serializer.expected @@ -12,3 +12,7 @@ obj.to_string(with thread format)=T0.52X obj.to_string(long thread format)=Ttttttttttttt0.52xxxxxxxxxxxxxxxxxxX obj.to_string(back to global format)=x0.524y obj.to_string(back to default format)=0.52381 +obj(12.0).to_string(default format)=12.0 +obj(12.0).to_string(%.0f)=12 +obj(12.0).to_string(%.0g)=1e+01 +obj(12.0).to_string(%.1g)=12.0 From c652b6ad29757857be328071ad7f9ca86d5275d4 Mon Sep 17 00:00:00 2001 From: Eric Haszlakiewicz Date: Sun, 24 Dec 2017 14:42:58 -0500 Subject: [PATCH 15/28] PR#394: fix breakage with VS build. --- json_object.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/json_object.c b/json_object.c index 52e8b76..8287163 100644 --- a/json_object.c +++ b/json_object.c @@ -809,6 +809,7 @@ static int json_object_double_to_json_string_format(struct json_object* jso, else { const char *std_format = "%.17g"; + int format_drops_decimals = 0; if (!format) { @@ -833,7 +834,6 @@ static int json_object_double_to_json_string_format(struct json_object* jso, else p = strchr(buf, '.'); - int format_drops_decimals = 0; if (format == std_format || strstr(format, ".0f") == NULL) format_drops_decimals = 1; From 250de31f17ff01b0a0d86a10640f91426618c385 Mon Sep 17 00:00:00 2001 From: Eric Haszlakiewicz Date: Mon, 15 Jan 2018 23:31:55 -0500 Subject: [PATCH 16/28] Bump the major version of the .so library generated up to 4.0 to avoid conflicts because some downstream packagers of json-c had already done their own bump to ".so.3" for a much older 0.12 release. --- Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index a0a43fc..034f0ab 100644 --- a/Makefile.am +++ b/Makefile.am @@ -43,7 +43,7 @@ noinst_HEADERS=\ random_seed.h \ strerror_override.h -libjson_c_la_LDFLAGS = -version-info 3:1:0 -no-undefined @JSON_BSYMBOLIC_LDFLAGS@ +libjson_c_la_LDFLAGS = -version-info 4:0:0 -no-undefined @JSON_BSYMBOLIC_LDFLAGS@ libjson_c_la_SOURCES = \ arraylist.c \ From cdc4e9f64bfdabfb556960f0179638097b981157 Mon Sep 17 00:00:00 2001 From: Jonathan Wiens Date: Wed, 17 Jan 2018 15:57:52 +0100 Subject: [PATCH 17/28] Avoid uninitialized variable warnings Fix json_object_object_foreach to avoid uninitialized variable warnings using ANSI C or MSC. --- json_object.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/json_object.h b/json_object.h index db63d22..a3a86c0 100644 --- a/json_object.h +++ b/json_object.h @@ -523,8 +523,8 @@ JSON_EXPORT void json_object_object_del(struct json_object* obj, const char *key #else /* ANSI C or MSC */ # define json_object_object_foreach(obj,key,val) \ - char *key;\ - struct json_object *val; \ + char *key = NULL;\ + struct json_object *val = NULL; \ struct lh_entry *entry ## key; \ struct lh_entry *entry_next ## key = NULL; \ for(entry ## key = json_object_get_object(obj)->head; \ From 1e0815083881f509893d320c87d0d470cad35d2d Mon Sep 17 00:00:00 2001 From: Chris Wolfe Date: Mon, 5 Feb 2018 19:24:51 -0600 Subject: [PATCH 18/28] pull in fuzzers, add CI scripts later --- ChangeLog | 3 +++ fuzz/README.md | 6 ++++++ fuzz/build.sh | 30 ++++++++++++++++++++++++++++++ fuzz/tokener_parse_ex_fuzzer.cc | 13 +++++++++++++ fuzz/tokener_parse_ex_fuzzer.dict | 18 ++++++++++++++++++ 5 files changed, 70 insertions(+) create mode 100644 fuzz/README.md create mode 100755 fuzz/build.sh create mode 100644 fuzz/tokener_parse_ex_fuzzer.cc create mode 100644 fuzz/tokener_parse_ex_fuzzer.dict diff --git a/ChangeLog b/ChangeLog index 5dd29ab..8f8aa8d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,9 @@ Deprecated and removed features: * lh_table_lookup() has been removed, use lh_table_lookup_ex() instead. * Remove TRUE and FALSE defines, use 1 and 0 instead. +Build changes: +-------------- +* Add a top level fuzz directory for fuzzers run by OSS-Fuzz 0.13 (up to commit 5dae561, 2017/11/29) ================================= diff --git a/fuzz/README.md b/fuzz/README.md new file mode 100644 index 0000000..237c1da --- /dev/null +++ b/fuzz/README.md @@ -0,0 +1,6 @@ +# Fuzzers + +This directory contains fuzzers that +target [llvm's LibFuzzer](https://llvm.org/docs/LibFuzzer.html). They are built +and run automatically by +Google's [OSS-Fuzz](https://github.com/google/oss-fuzz/) infrastructure. diff --git a/fuzz/build.sh b/fuzz/build.sh new file mode 100755 index 0000000..30c3f77 --- /dev/null +++ b/fuzz/build.sh @@ -0,0 +1,30 @@ +#!/bin/bash -eu +# Copyright 2018 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ + +./autogen.sh +./configure --enable-static --disable-shared +make -j$(nproc) all +ar rc json_c.a *.o + +cp $SRC/*.dict $OUT/ + +for f in $SRC/*_fuzzer.cc; do + fuzzer=$(basename "$f" _fuzzer.cc) + $CXX $CXXFLAGS -std=c++11 -I$SRC/json-c \ + $SRC/${fuzzer}_fuzzer.cc -o $OUT/${fuzzer}_fuzzer \ + -lFuzzingEngine $SRC/json-c/json_c.a +done diff --git a/fuzz/tokener_parse_ex_fuzzer.cc b/fuzz/tokener_parse_ex_fuzzer.cc new file mode 100644 index 0000000..c0a1c3d --- /dev/null +++ b/fuzz/tokener_parse_ex_fuzzer.cc @@ -0,0 +1,13 @@ +#include + +#include + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + const char *data1 = reinterpret_cast(data); + json_tokener *tok = json_tokener_new(); + json_object *obj = json_tokener_parse_ex(tok, data1, size); + + json_object_put(obj); + json_tokener_free(tok); + return 0; +} diff --git a/fuzz/tokener_parse_ex_fuzzer.dict b/fuzz/tokener_parse_ex_fuzzer.dict new file mode 100644 index 0000000..23c6fa2 --- /dev/null +++ b/fuzz/tokener_parse_ex_fuzzer.dict @@ -0,0 +1,18 @@ +"{" +"}" +"," +"[" +"]" +"," +":" +"e" +"e+" +"e-" +"E" +"E+" +"E-" +"\"" +"null" +"1" +"1.234" +"3e4" From 2fd95844c38de8b9b35a3d75f917ccfd1e182743 Mon Sep 17 00:00:00 2001 From: Eric Haszlakiewicz Date: Sun, 4 Mar 2018 22:32:45 -0500 Subject: [PATCH 19/28] Issue #396: check for toolchain compatibilty with _REENTRANT before adding it to CFLAGS. --- configure.ac | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index ef556eb..272ea6a 100644 --- a/configure.ac +++ b/configure.ac @@ -167,7 +167,28 @@ AC_SUBST(JSON_BSYMBOLIC_LDFLAGS) AX_APPEND_COMPILE_FLAGS([-Wall -Werror -Wcast-qual -Wno-error=deprecated-declarations]) AX_APPEND_COMPILE_FLAGS([-Wextra -Wwrite-string -Wno-unused-parameter]) -AX_APPEND_COMPILE_FLAGS([-D_GNU_SOURCE -D_REENTRANT]) +AX_APPEND_COMPILE_FLAGS([-D_GNU_SOURCE]) + +AC_LANG_PUSH([C]) +AC_MSG_CHECKING([for compatibility with _REENTRANT and toolchain headers]) +AC_LINK_IFELSE( +[ + AC_LANG_SOURCE([[ +/* uClibc toolchains without threading barf when _REENTRANT is defined */ +#define _REENTRANT 1 +#include +int main () +{ + return 0; +} +]])], [ + AC_MSG_RESULT(yes) + AX_APPEND_COMPILE_FLAGS([-D_REENTRANT]) +], [ + AC_MSG_RESULT(no) +]) +AC_LANG_POP([C]) + AX_COMPILE_CHECK_SIZEOF(int) AX_COMPILE_CHECK_SIZEOF(long) From 104aef0a6e2047d977a19a57af70c4a0460cfa39 Mon Sep 17 00:00:00 2001 From: Eric Haszlakiewicz Date: Mon, 5 Mar 2018 22:54:57 -0500 Subject: [PATCH 20/28] Update the change log for the 0.13.1 release. --- ChangeLog | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ChangeLog b/ChangeLog index 8f8aa8d..812a483 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,8 +11,21 @@ Deprecated and removed features: Build changes: -------------- + +0.13.1 (up to commit 0f814e5, 2018/03/04) +========================================= + +* Bump the major version of the .so library generated up to 4.0 to avoid + conflicts because some downstream packagers of json-c had already done + their own bump to ".so.3" for a much older 0.12 release. +* Add const size_t json_c_object_sizeof() +* Avoid invalid free (and thus a segfault) when ref_count gets < 0 +* PR#394: fix handling of custom double formats that include a ".0" +* Avoid uninitialized variable warnings in json_object_object_foreach +* Issue #396: fix build for certain uClibc based systems. * Add a top level fuzz directory for fuzzers run by OSS-Fuzz + 0.13 (up to commit 5dae561, 2017/11/29) ================================= From da4b34355da023c439e96bc6ca31886cd69d6bdb Mon Sep 17 00:00:00 2001 From: Eric Haszlakiewicz Date: Sun, 25 Mar 2018 18:23:42 -0400 Subject: [PATCH 21/28] Add an parse test for content starting with a UTF8 BOM, which is _not_ a valid start to a JSON message. --- tests/test_parse.c | 16 +++++++++++++++- tests/test_parse.expected | 5 ++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/tests/test_parse.c b/tests/test_parse.c index ee1f838..f46651b 100644 --- a/tests/test_parse.c +++ b/tests/test_parse.c @@ -9,6 +9,7 @@ #include "json_visit.h" static void test_basic_parse(void); +static void test_utf8_parse(void); static void test_verbose_parse(void); static void test_incremental_parse(void); @@ -19,6 +20,8 @@ int main(void) static const char separator[] = "=================================="; test_basic_parse(); puts(separator); + test_utf8_parse(); + puts(separator); test_verbose_parse(); puts(separator); test_incremental_parse(); @@ -107,6 +110,17 @@ static void test_basic_parse() single_basic_parse("[18446744073709551616]", 1); } +static void test_utf8_parse() +{ + // json_tokener_parse doesn't support checking for byte order marks. + // It's the responsibility of the caller to detect and skip a BOM. + // Both of these checks return null. + char utf8_bom[] = { 0xEF, 0xBB, 0xBF, 0x00 }; + char utf8_bom_and_chars[] = { 0xEF, 0xBB, 0xBF, '{', '}', 0x00 }; + single_basic_parse(utf8_bom, 0); + single_basic_parse(utf8_bom_and_chars, 0); +} + // Clear the re-serialization information that the tokener // saves to ensure that the output reflects the actual // values we parsed, rather than just the original input. @@ -145,7 +159,7 @@ static void test_verbose_parse() /* b/c the string starts with 'f' parsing return a boolean error */ assert (error == json_tokener_error_parse_boolean); - puts("json_tokener_parse_versbose() OK"); + puts("json_tokener_parse_verbose() OK"); } struct incremental_step { diff --git a/tests/test_parse.expected b/tests/test_parse.expected index ada6141..5d3976a 100644 --- a/tests/test_parse.expected +++ b/tests/test_parse.expected @@ -51,7 +51,10 @@ new_obj.to_string([0e+])=[ 0.0 ] new_obj.to_string([0e+-1])=null new_obj.to_string([18446744073709551616])=[ 9223372036854775807 ] ================================== -json_tokener_parse_versbose() OK +new_obj.to_string()=null +new_obj.to_string({})=null +================================== +json_tokener_parse_verbose() OK ================================== Starting incremental tests. Note: quotes and backslashes seen in the output here are literal values passed From f8c632f579c71012f9aca81543b880a579f634fc Mon Sep 17 00:00:00 2001 From: Eric Haszlakiewicz Date: Sun, 25 Mar 2018 18:25:58 -0400 Subject: [PATCH 22/28] Issue #407: fix incorrect casts in calls to ctype functions (isdigit and isspace) so we don't crash when asserts are enabled on certain platforms and characters > 128 are parsed. --- json_object.c | 2 +- json_pointer.c | 4 ++-- json_tokener.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/json_object.c b/json_object.c index 8287163..8a86bc6 100644 --- a/json_object.c +++ b/json_object.c @@ -838,7 +838,7 @@ static int json_object_double_to_json_string_format(struct json_object* jso, format_drops_decimals = 1; if (size < (int)sizeof(buf) - 2 && - isdigit((int)buf[0]) && /* Looks like *some* kind of number */ + isdigit((unsigned char)buf[0]) && /* Looks like *some* kind of number */ !p && /* Has no decimal point */ strchr(buf, 'e') == NULL && /* Not scientific notation */ format_drops_decimals) diff --git a/json_pointer.c b/json_pointer.c index 2b2a9ef..c7e34f7 100644 --- a/json_pointer.c +++ b/json_pointer.c @@ -44,7 +44,7 @@ static int is_valid_index(struct json_object *jo, const char *path, int32_t *idx /* this code-path optimizes a bit, for when we reference the 0-9 index range in a JSON array and because leading zeros not allowed */ if (len == 1) { - if (isdigit((int)path[0])) { + if (isdigit((unsigned char)path[0])) { *idx = (path[0] - '0'); goto check_oob; } @@ -58,7 +58,7 @@ static int is_valid_index(struct json_object *jo, const char *path, int32_t *idx } /* RFC states base-10 decimals */ for (i = 0; i < len; i++) { - if (!isdigit((int)path[i])) { + if (!isdigit((unsigned char)path[i])) { errno = EINVAL; return 0; } diff --git a/json_tokener.c b/json_tokener.c index 449a82d..561f730 100644 --- a/json_tokener.c +++ b/json_tokener.c @@ -295,7 +295,7 @@ struct json_object* json_tokener_parse_ex(struct json_tokener *tok, case json_tokener_state_eatws: /* Advance until we change state */ - while (isspace((int)c)) { + while (isspace((unsigned char)c)) { if ((!ADVANCE_CHAR(str, tok)) || (!PEEK_CHAR(c, tok))) goto out; } From 8bd62177e796386fb6382db101c90b57b6138afe Mon Sep 17 00:00:00 2001 From: janczer Date: Tue, 24 Apr 2018 16:00:38 +0200 Subject: [PATCH 23/28] Fixed typos --- STYLE.txt | 2 +- json_object.h | 18 +++++++++--------- json_pointer.c | 2 +- tests/test_compare.c | 12 ++++++------ tests/test_compare.expected | 6 +++--- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/STYLE.txt b/STYLE.txt index e5acd14..195883c 100755 --- a/STYLE.txt +++ b/STYLE.txt @@ -7,7 +7,7 @@ Official json-c style: Aim for readability, not strict conformance to fixed style rules. These rules are not comprehensive. Look to existing code for guidelines. Indentation is tab based, with continuations of long lines starting with tabs then spaces for alignment. -Try to line up components of continuation lines with corresponding part of the line above (i.e. "indent -lp" effect), but avoid excessive identation tha causes extra line wraps. +Try to line up components of continuation lines with corresponding part of the line above (i.e. "indent -lp" effect), but avoid excessive indentation tha causes extra line wraps. e.g. (T=tab, S=space): TTTTsome_long_func_call(arg1, arg2, TTTTSSSSSSSSSSSSSSSSSSSarg3, arg4); diff --git a/json_object.h b/json_object.h index a3a86c0..30341bc 100644 --- a/json_object.h +++ b/json_object.h @@ -91,7 +91,7 @@ extern "C" { /** * A flag for the json_object_object_add_ex function which * causes the value to be added without a check if it already exists. - * Note: it is the responsibilty of the caller to ensure that no + * Note: it is the responsibility of the caller to ensure that no * key is added multiple times. If this is done, results are * unpredictable. While this option is somewhat dangerous, it * permits potentially large performance savings in code that @@ -442,7 +442,7 @@ JSON_EXPORT int json_object_object_add_ex(struct json_object* obj, * * This returns NULL if the field is found but its value is null, or if * the field is not found, or if obj is not a json_type_object. If you - * need to distinguis between these cases, use json_object_object_get_ex(). + * need to distinguish between these cases, use json_object_object_get_ex(). * * *No* reference counts will be changed. There is no need to manually adjust * reference counts through the json_object_put/json_object_get methods unless @@ -624,7 +624,7 @@ JSON_EXPORT int json_object_array_add(struct json_object *obj, JSON_EXPORT int json_object_array_put_idx(struct json_object *obj, size_t idx, struct json_object *val); -/** Get the element at specificed index of the array (a json_object of type json_type_array) +/** Get the element at specified index of the array (a json_object of type json_type_array) * @param obj the json_object instance * @param idx the index to get the element at * @returns the json_object at the specified index (or NULL) @@ -671,7 +671,7 @@ JSON_EXPORT json_bool json_object_get_boolean(const struct json_object *obj); * * The type of obj is checked to be a json_type_boolean and 0 is returned * if it is not without any further actions. If type of obj is json_type_boolean - * the obect value is chaned to new_value + * the object value is changed to new_value * * @param obj the json_object instance * @param new_value the value to be set @@ -718,7 +718,7 @@ JSON_EXPORT int32_t json_object_get_int(const struct json_object *obj); * * The type of obj is checked to be a json_type_int and 0 is returned * if it is not without any further actions. If type of obj is json_type_int - * the obect value is changed to new_value + * the object value is changed to new_value * * @param obj the json_object instance * @param new_value the value to be set @@ -763,7 +763,7 @@ JSON_EXPORT int64_t json_object_get_int64(const struct json_object *obj); * * The type of obj is checked to be a json_type_int and 0 is returned * if it is not without any further actions. If type of obj is json_type_int - * the obect value is chaned to new_value + * the object value is changed to new_value * * @param obj the json_object instance * @param new_value the value to be set @@ -880,7 +880,7 @@ JSON_EXPORT double json_object_get_double(const struct json_object *obj); * * The type of obj is checked to be a json_type_double and 0 is returned * if it is not without any further actions. If type of obj is json_type_double - * the obect value is chaned to new_value + * the object value is changed to new_value * * @param obj the json_object instance * @param new_value the value to be set @@ -942,10 +942,10 @@ JSON_EXPORT int json_object_set_string(json_object* obj, const char* new_value); * * The type of obj is checked to be a json_type_string and 0 is returned * if it is not without any further actions. If type of obj is json_type_string - * the obect value is chaned to new_value + * the object value is changed to new_value * * @param obj the json_object instance - * @param new_value the value to be set; Since string legth is given in len this need not be zero terminated + * @param new_value the value to be set; Since string length is given in len this need not be zero terminated * @param len the length of new_value * @returns 1 if value is set correctly, 0 otherwise */ diff --git a/json_pointer.c b/json_pointer.c index c7e34f7..9531c03 100644 --- a/json_pointer.c +++ b/json_pointer.c @@ -28,7 +28,7 @@ static void string_replace_all_occurrences_with_char(char *s, const char *occur, char repl_char) { int slen = strlen(s); - int skip = strlen(occur) - 1; /* length of the occurence, minus the char we're replacing */ + int skip = strlen(occur) - 1; /* length of the occurrence, minus the char we're replacing */ char *p = s; while ((p = strstr(p, occur))) { *p = repl_char; diff --git a/tests/test_compare.c b/tests/test_compare.c index c7e44f6..cba328c 100644 --- a/tests/test_compare.c +++ b/tests/test_compare.c @@ -18,19 +18,19 @@ int main() struct json_object *int3 = json_object_new_int(1); if (!json_object_equal(int1, int2)) - printf("JSON integer comparision is correct\n"); + printf("JSON integer comparison is correct\n"); else - printf("JSON integer comparision failed\n"); + printf("JSON integer comparison failed\n"); if (json_object_equal(int1, int1)) - printf("JSON same object comparision is correct\n"); + printf("JSON same object comparison is correct\n"); else - printf("JSON same object comparision failed\n"); + printf("JSON same object comparison failed\n"); if (json_object_equal(int2, int3)) - printf("JSON same integer comparision is correct\n"); + printf("JSON same integer comparison is correct\n"); else - printf("JSON same integer comparision failed\n"); + printf("JSON same integer comparison failed\n"); json_object_put(int1); json_object_put(int2); diff --git a/tests/test_compare.expected b/tests/test_compare.expected index 46f03c4..5468f83 100644 --- a/tests/test_compare.expected +++ b/tests/test_compare.expected @@ -1,6 +1,6 @@ -JSON integer comparision is correct -JSON same object comparision is correct -JSON same integer comparision is correct +JSON integer comparison is correct +JSON same object comparison is correct +JSON same integer comparison is correct Comparing equal strings is correct Comparing different strings is correct Comparing equal doubles is correct From dfc0fddf225eecb3302fe1a9beac133be3536cd5 Mon Sep 17 00:00:00 2001 From: Eric Haszlakiewicz Date: Sun, 27 May 2018 16:07:11 -0400 Subject: [PATCH 24/28] Include the json-c.lib, .pdb and .exp files in the zip file created by the appveyor build, since it seems they're needed for linking and debugging. --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 72b1331..8df0560 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -32,7 +32,7 @@ after_build: - copy json_inttypes.h include\json-c\* - copy include\json_config.h include\json-c\* - copy json_object_private.h include\json-c\* -- 7z a json-c.lib.zip lib\json-c.dll include\json-c\*.h +- 7z a json-c.lib.zip lib\json-c.dll Debug\json-c.lib Debug\json-c.exp Debug\json-c.pdb include\json-c\*.h artifacts: - path: json-c.lib.zip From 7038bb8061226ce894f9fc1b67d410f5203b7a29 Mon Sep 17 00:00:00 2001 From: Eric Haszlakiewicz Date: Sun, 27 May 2018 18:20:32 -0400 Subject: [PATCH 25/28] Try the appveyor changes again, using %Configuration% instead of "Debug" --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 8df0560..ea3de8c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -32,7 +32,7 @@ after_build: - copy json_inttypes.h include\json-c\* - copy include\json_config.h include\json-c\* - copy json_object_private.h include\json-c\* -- 7z a json-c.lib.zip lib\json-c.dll Debug\json-c.lib Debug\json-c.exp Debug\json-c.pdb include\json-c\*.h +- 7z a json-c.lib.zip lib\json-c.dll %Configuration%\json-c.lib %Configuration%\json-c.exp %Configuration%\json-c.pdb include\json-c\*.h artifacts: - path: json-c.lib.zip From 4414d068b308bff4fd98c83e1ae08346913f93c4 Mon Sep 17 00:00:00 2001 From: Eric Haszlakiewicz Date: Sun, 27 May 2018 21:50:57 -0400 Subject: [PATCH 26/28] Always create debug info (pdb file) even for release builds. --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 36b61a5..0e8d40f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,11 @@ endif () if(MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4100 /wd4996 /wd4244 /wd4706 /wd4702 /wd4127 /wd4701") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4100 /wd4996 /wd4244 /wd4706 /wd4702 /wd4127 /wd4701") + # Always create debug info (pdb file), even for release builds + set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG") + set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} /DEBUG") + set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG") + set(CMAKE_STATIC_LINKER_FLAGS_RELEASE "${CMAKE_STATIC_LINKER_FLAGS_RELEASE} /DEBUG") set(cmake_create_config 1) elseif(MINGW) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -D_GNU_SOURCE=1") From 7a4759f16509a734c6db9bb01677d534da00d455 Mon Sep 17 00:00:00 2001 From: max Date: Fri, 1 Jun 2018 18:21:06 +0300 Subject: [PATCH 27/28] arraylist: Fix names of parameters for callback function --- arraylist.c | 8 ++++---- arraylist.h | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/arraylist.c b/arraylist.c index ddeb8d4..8a88ed1 100644 --- a/arraylist.c +++ b/arraylist.c @@ -112,16 +112,16 @@ array_list_add(struct array_list *arr, void *data) } void -array_list_sort(struct array_list *arr, int(*sort_fn)(const void *, const void *)) +array_list_sort(struct array_list *arr, int(*compar)(const void *, const void *)) { - qsort(arr->array, arr->length, sizeof(arr->array[0]), sort_fn); + qsort(arr->array, arr->length, sizeof(arr->array[0]), compar); } void* array_list_bsearch(const void **key, struct array_list *arr, - int (*sort_fn)(const void *, const void *)) + int (*compar)(const void *, const void *)) { return bsearch(key, arr->array, arr->length, sizeof(arr->array[0]), - sort_fn); + compar); } size_t diff --git a/arraylist.h b/arraylist.h index 38603e8..a0d767e 100644 --- a/arraylist.h +++ b/arraylist.h @@ -56,9 +56,9 @@ array_list_length(struct array_list *al); extern void array_list_sort(struct array_list *arr, int(*compar)(const void *, const void *)); -extern void* array_list_bsearch(const void **key, - struct array_list *arr, - int (*sort_fn)(const void *, const void *)); +extern void* +array_list_bsearch(const void **key, struct array_list *arr, + int (*compar)(const void *, const void *)); extern int array_list_del_idx(struct array_list *arr, size_t idx, size_t count); From 37a2edf468967170ee4f3f5641634cd709d8831f Mon Sep 17 00:00:00 2001 From: Keith Holman Date: Thu, 7 Jun 2018 13:19:27 -0400 Subject: [PATCH 28/28] install json_object_iterator.h header file When building the project using cmake then installing it. The definitions in `json_object_iterator.h` are required but not installed by the cmake install rule. This patch adds the `json_object_iterator.h` file to the list of files to install. Signed-off-by: Keith Holman --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e8d40f..967eff3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,6 +71,7 @@ set(JSON_C_PUBLIC_HEADERS ./json_c_version.h ./json_inttypes.h ./json_object.h + ./json_object_iterator.h ./json_pointer.h ./json_tokener.h ./json_util.h