mirror of
https://github.com/json-c/json-c.git
synced 2026-04-03 04:19:07 +08:00
Compare commits
38 Commits
json-c-0.1
...
disallow-c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6bfab90c87 | ||
|
|
ecb7a4c9a3 | ||
|
|
906d1581de | ||
|
|
9b8d170d1f | ||
|
|
6e481aa061 | ||
|
|
781675758f | ||
|
|
833233faa8 | ||
|
|
31a22fb2da | ||
|
|
0051f2dbe0 | ||
|
|
0741ce3918 | ||
|
|
e3464a2ab4 | ||
|
|
61016412fb | ||
|
|
f2eac07129 | ||
|
|
e93ae70417 | ||
|
|
0bc2dd5e60 | ||
|
|
9c44c7ed52 | ||
|
|
401249cbdf | ||
|
|
66f7869219 | ||
|
|
dabed80523 | ||
|
|
f6c8eba84e | ||
|
|
76f819e51d | ||
|
|
eef983b1df | ||
|
|
c0cf4bc23b | ||
|
|
e85c8ada54 | ||
|
|
2c84476c77 | ||
|
|
407ddb4350 | ||
|
|
33337523f5 | ||
|
|
7ff7eab603 | ||
|
|
88bce2b38e | ||
|
|
a907f7dd1b | ||
|
|
ad8b8afa7d | ||
|
|
4186537557 | ||
|
|
9ff6b68baf | ||
|
|
1a7defaa69 | ||
|
|
c4a615a052 | ||
|
|
159822dd8a | ||
|
|
990acb4e19 | ||
|
|
502522a93d |
@@ -3,24 +3,11 @@
|
||||
# and many OpenWRT packages require, much newer CMake packages.
|
||||
# We're stopping before 3.10 because that version starts requiring
|
||||
# c++11, which isn't available on e.g HPUX.
|
||||
cmake_minimum_required(VERSION 3.9)
|
||||
|
||||
# The project() command manages VERSION variables.
|
||||
cmake_policy(SET CMP0048 NEW)
|
||||
cmake_minimum_required(VERSION 3.9...3.12)
|
||||
|
||||
# JSON-C library is C only project.
|
||||
# PROJECT_VERSION{,_MAJOR,_MINOR,_PATCH} set by project():
|
||||
project(json-c LANGUAGES C VERSION 0.16.99)
|
||||
|
||||
# Targets may not link directly to themselves.
|
||||
cmake_policy(SET CMP0038 NEW)
|
||||
|
||||
# MACOSX_RPATH is enabled by default.
|
||||
# We set it explicitly to avoid the warning
|
||||
cmake_policy(SET CMP0042 NEW)
|
||||
|
||||
# Only interpret if() arguments as variables or keywords when unquoted.
|
||||
cmake_policy(SET CMP0054 NEW)
|
||||
project(json-c LANGUAGES C VERSION 0.17.99)
|
||||
|
||||
# set default build type if not specified by user
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
@@ -29,13 +16,6 @@ endif()
|
||||
|
||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2")
|
||||
|
||||
# Include file check macros honor CMAKE_REQUIRED_LIBRARIES
|
||||
# i.e. the check_include_file() calls will include -lm when checking.
|
||||
# New in version 3.12.
|
||||
if(POLICY CMP0075)
|
||||
cmake_policy(SET CMP0075 NEW)
|
||||
endif()
|
||||
|
||||
include(CTest)
|
||||
|
||||
# Set some packaging variables.
|
||||
@@ -197,9 +177,10 @@ endif()
|
||||
|
||||
# uClibc *intentionally* crashes in duplocale(), at least as of:
|
||||
# https://github.com/ffainelli/uClibc/blob/266bdc1/libc/misc/locale/locale.c#L1322
|
||||
# So, if it looks like we're compiling for a system like that just disable
|
||||
# So, if it looks like we're compiling for a system like that just disable
|
||||
# locale handling entirely.
|
||||
exec_program(${CMAKE_C_COMPILER} ARGS -dumpmachine OUTPUT_VARIABLE CMAKE_GNU_C_MACHINE)
|
||||
execute_process (COMMAND ${CMAKE_C_COMPILER} -dumpmachine ERROR_QUIET OUTPUT_VARIABLE CMAKE_GNU_C_MACHINE)
|
||||
|
||||
if (CMAKE_GNU_C_MACHINE MATCHES "uclibc")
|
||||
message(STATUS "Detected uClibc compiler, disabling locale handling")
|
||||
set(HAVE_SETLOCALE 0)
|
||||
@@ -295,7 +276,24 @@ message(STATUS "Wrote ${PROJECT_BINARY_DIR}/config.h")
|
||||
configure_file(${PROJECT_SOURCE_DIR}/cmake/json_config.h.in ${PROJECT_BINARY_DIR}/json_config.h)
|
||||
message(STATUS "Wrote ${PROJECT_BINARY_DIR}/json_config.h")
|
||||
|
||||
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
|
||||
if (NOT DEFINED CMAKE_C_COMPILER_FRONTEND_VARIANT OR "${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "") # only available in cmake 3.14+
|
||||
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
|
||||
set(CMAKE_C_COMPILER_FRONTEND_VARIANT "MSVC")
|
||||
elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
|
||||
set(CMAKE_C_COMPILER_FRONTEND_VARIANT "GNU")
|
||||
elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
|
||||
# Detect clang-cl.exe, it is Clang but with MSVC compatible command line arguments
|
||||
execute_process (COMMAND ${CMAKE_C_COMPILER} -? ERROR_QUIET OUTPUT_QUIET RESULT_VARIABLE _clang_result)
|
||||
if (_clang_result EQUAL 0)
|
||||
set(CMAKE_C_COMPILER_FRONTEND_VARIANT "MSVC")
|
||||
else()
|
||||
set(CMAKE_C_COMPILER_FRONTEND_VARIANT "GNU")
|
||||
message(STATUS, "clang result is NOT 0")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if ("${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "GNU" OR "${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "Clang")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections")
|
||||
if ("${DISABLE_WERROR}" STREQUAL "OFF")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
|
||||
@@ -312,11 +310,11 @@ if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_C_COMPILER_ID}" STREQUAL
|
||||
|
||||
add_definitions(-D_GNU_SOURCE)
|
||||
|
||||
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
|
||||
if ("${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "Clang")
|
||||
# Remove this for 1.0 when we can bump the ABI and actually fix these warnings.
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-shorten-64-to-32")
|
||||
endif()
|
||||
elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
|
||||
elseif ("${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DEBUG")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4100")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4996")
|
||||
@@ -327,7 +325,7 @@ elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4701")
|
||||
endif()
|
||||
|
||||
if (NOT ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC"))
|
||||
if (NOT ("${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC"))
|
||||
check_c_source_compiles(
|
||||
"
|
||||
/* uClibc toolchains without threading barf when _REENTRANT is defined */
|
||||
@@ -472,7 +470,7 @@ add_library(${PROJECT_NAME}
|
||||
${JSON_C_HEADERS}
|
||||
)
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
VERSION 5.2.0
|
||||
VERSION 5.3.0
|
||||
SOVERSION 5)
|
||||
list(APPEND CMAKE_TARGETS ${PROJECT_NAME})
|
||||
# If json-c is used as subroject it set to target correct interface -I flags and allow
|
||||
@@ -545,7 +543,6 @@ install(
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
|
||||
)
|
||||
|
||||
if (UNIX OR MINGW OR CYGWIN)
|
||||
SET(prefix ${CMAKE_INSTALL_PREFIX})
|
||||
# exec_prefix is prefix by default and CMake does not have the
|
||||
# concept.
|
||||
@@ -573,7 +570,6 @@ if (UNIX OR MINGW OR CYGWIN)
|
||||
configure_file(json-c.pc.in json-c.pc @ONLY)
|
||||
set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files")
|
||||
install(FILES ${PROJECT_BINARY_DIR}/json-c.pc DESTINATION "${INSTALL_PKGCONFIG_DIR}")
|
||||
endif ()
|
||||
|
||||
install(FILES ${JSON_C_PUBLIC_HEADERS} DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}/json-c)
|
||||
|
||||
@@ -589,4 +585,3 @@ if (NOT MSVC) # cmd line apps don't built on Windows currently.
|
||||
add_subdirectory(apps)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
35
README.md
35
README.md
@@ -1,6 +1,6 @@
|
||||
\mainpage
|
||||
|
||||
`json-c`
|
||||
json-c
|
||||
========
|
||||
|
||||
1. [Overview and Build Status](#overview)
|
||||
@@ -15,7 +15,8 @@
|
||||
7. [Linking to libjson-c](#linking)
|
||||
8. [Using json-c](#using)
|
||||
|
||||
JSON-C - A JSON implementation in C <a name="overview"></a>
|
||||
<a name="overview"></a>
|
||||
JSON-C - A JSON implementation in C
|
||||
-----------------------------------
|
||||
|
||||
JSON-C implements a reference counting object model that allows you to easily
|
||||
@@ -29,7 +30,8 @@ if you already have json-c installed and ready to use.
|
||||
|
||||
Home page for json-c: https://github.com/json-c/json-c/wiki
|
||||
|
||||
Getting Help <a name="gettinghelp"></a>
|
||||
<a name="gettinghelp"></a>
|
||||
Getting Help
|
||||
------------
|
||||
|
||||
If you have questions about using json-c, please start a thread on
|
||||
@@ -47,7 +49,8 @@ features or large changes of any kind, please first start a discussion
|
||||
on the [forums](https://groups.google.com/forum/#!forum/json-c).
|
||||
|
||||
|
||||
Building on Unix with `git`, `gcc` and `cmake` <a name="buildunix"></a>
|
||||
<a name="buildunix"></a>
|
||||
Building on Unix with `git`, `gcc` and `cmake`
|
||||
--------------------------------------------------
|
||||
|
||||
If you already have json-c installed, see [Linking to `libjson-c`](#linking)
|
||||
@@ -60,7 +63,8 @@ Build Status
|
||||
Test Status
|
||||
* [Coveralls](https://coveralls.io/github/json-c/json-c?branch=master) [](https://coveralls.io/github/json-c/json-c?branch=master)
|
||||
|
||||
### Prerequisites: <a name="installprereq"></a>
|
||||
<a name="installprereq"></a>
|
||||
### Prerequisites:
|
||||
|
||||
- `gcc`, `clang`, or another C compiler
|
||||
|
||||
@@ -80,7 +84,8 @@ sudo apt install doxygen # optional
|
||||
sudo apt install valgrind # optional
|
||||
```
|
||||
|
||||
### Build instructions: <a name="buildcmds"></a>
|
||||
<a name="buildcmds"></a>
|
||||
### Build instructions:
|
||||
|
||||
`json-c` GitHub repo: https://github.com/json-c/json-c
|
||||
|
||||
@@ -116,7 +121,8 @@ google-chrome doc/html/index.html
|
||||
```
|
||||
|
||||
|
||||
CMake Options <a name="CMake"></a>
|
||||
<a name="CMake"></a>
|
||||
CMake Options
|
||||
--------------------
|
||||
|
||||
The json-c library is built with [CMake](https://cmake.org/cmake-tutorial/),
|
||||
@@ -188,7 +194,8 @@ cmake-configure can take a few options.
|
||||
| disable-werror | Avoid treating compiler warnings as fatal errors |
|
||||
|
||||
|
||||
Testing: <a name="testing"></a>
|
||||
<a name="testing"></a>
|
||||
Testing:
|
||||
----------
|
||||
|
||||
By default, if valgrind is available running tests uses it.
|
||||
@@ -224,7 +231,8 @@ JSONC_TEST_TRACE=1 make test
|
||||
and check the log files again.
|
||||
|
||||
|
||||
Building on Unix and Windows with `vcpkg` <a name="buildvcpkg"></a>
|
||||
<a name="buildvcpkg"></a>
|
||||
Building on Unix and Windows with `vcpkg`
|
||||
--------------------------------------------------
|
||||
|
||||
You can download and install JSON-C using the [vcpkg](https://github.com/Microsoft/vcpkg/) dependency manager:
|
||||
@@ -237,7 +245,8 @@ You can download and install JSON-C using the [vcpkg](https://github.com/Microso
|
||||
|
||||
The JSON-C port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.
|
||||
|
||||
Building for Android <a name="android">
|
||||
<a name="android">
|
||||
Building for Android
|
||||
----------------------
|
||||
|
||||
Building on Android is now particularly well supported, but there
|
||||
@@ -261,7 +270,8 @@ cmake \
|
||||
make install
|
||||
```
|
||||
|
||||
Linking to `libjson-c` <a name="linking">
|
||||
<a name="linking">
|
||||
Linking to `libjson-c`
|
||||
----------------------
|
||||
|
||||
If your system has `pkgconfig`,
|
||||
@@ -298,7 +308,8 @@ cd build
|
||||
cmake -DCMAKE_PREFIX_PATH=/path/to/json_c/install/lib64/cmake ..
|
||||
```
|
||||
|
||||
Using json-c <a name="using">
|
||||
<a name="using">
|
||||
Using json-c
|
||||
------------
|
||||
|
||||
To use json-c you can either include json.h, or preferably, one of the
|
||||
|
||||
@@ -141,12 +141,10 @@ Use ${release}.99 to indicate a version "newer" than anything on the branch:
|
||||
Update the version in json_c_version.h
|
||||
Update the version in CMakeLists.txt
|
||||
|
||||
Update RELEASE_CHECKLIST.txt, set release=${release}+1
|
||||
Update the set_target_properties() line in CmakeLists.txt to match the release branch.
|
||||
|
||||
Add a new empty section to the json-c.sym file, for ${release}+1
|
||||
|
||||
Update the set_target_properties() line in CmakeLists.txt to match the release branch.
|
||||
|
||||
git commit -a -m "Update the master branch to version ${release}.99"
|
||||
git push
|
||||
|
||||
|
||||
@@ -8,11 +8,13 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
json_tokener *tok = json_tokener_new();
|
||||
json_object *obj = json_tokener_parse_ex(tok, data1, size);
|
||||
|
||||
json_object_object_foreach(jobj, key, val) {
|
||||
(void)json_object_get_type(val);
|
||||
(void)json_object_get_string(val);
|
||||
if (json_object_is_type(obj, json_type_object)) {
|
||||
json_object_object_foreach(obj, key, val) {
|
||||
(void)json_object_get_type(val);
|
||||
(void)json_object_get_string(val);
|
||||
}
|
||||
}
|
||||
(void)json_object_to_json_string(obj, JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED);
|
||||
(void)json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED);
|
||||
|
||||
json_object_put(obj);
|
||||
json_tokener_free(tok);
|
||||
|
||||
@@ -176,3 +176,7 @@ JSONC_0.17 {
|
||||
json_patch_apply;
|
||||
# array_list_insert_idx is intentionally not exported
|
||||
} JSONC_0.16;
|
||||
|
||||
JSONC_0.18 {
|
||||
# global:
|
||||
} JSONC_0.17;
|
||||
|
||||
@@ -17,11 +17,11 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#define JSON_C_MAJOR_VERSION 0
|
||||
#define JSON_C_MINOR_VERSION 16
|
||||
#define JSON_C_MINOR_VERSION 17
|
||||
#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.16.99"
|
||||
#define JSON_C_VERSION "0.17.99"
|
||||
|
||||
#ifndef JSON_EXPORT
|
||||
#if defined(_MSC_VER) && defined(JSON_C_DLL)
|
||||
|
||||
@@ -172,10 +172,10 @@ JSON_EXPORT struct json_object *json_object_get(struct json_object *obj);
|
||||
* is a member of (unless you know you've called `json_object_get(obj)` to
|
||||
* explicitly increment the refcount).
|
||||
*
|
||||
* NULL may be passed, which which case this is a no-op.
|
||||
* NULL may be passed, in which case this is a no-op.
|
||||
*
|
||||
* @param obj the json_object instance
|
||||
* @returns 1 if the object was freed.
|
||||
* @returns 1 if the object was freed, 0 if only the refcount was decremented
|
||||
* @see json_object_get()
|
||||
*/
|
||||
JSON_EXPORT int json_object_put(struct json_object *obj);
|
||||
@@ -191,6 +191,7 @@ JSON_EXPORT int json_object_put(struct json_object *obj);
|
||||
json_type_object,
|
||||
json_type_array,
|
||||
json_type_string
|
||||
* @returns 1 if the object is of the specified type, 0 otherwise
|
||||
*/
|
||||
JSON_EXPORT int json_object_is_type(const struct json_object *obj, enum json_type type);
|
||||
|
||||
@@ -458,9 +459,9 @@ JSON_EXPORT struct json_object *json_object_object_get(const struct json_object
|
||||
* associated with the given field name.
|
||||
*
|
||||
* It is safe to pass a NULL value.
|
||||
* @returns whether or not the key exists
|
||||
* @returns 1 if the key exists, 0 otherwise
|
||||
*/
|
||||
JSON_EXPORT json_bool json_object_object_get_ex(const struct json_object *obj, const char *key,
|
||||
JSON_EXPORT int json_object_object_get_ex(const struct json_object *obj, const char *key,
|
||||
struct json_object **value);
|
||||
|
||||
/** Delete the given json_object field
|
||||
@@ -560,7 +561,7 @@ JSON_EXPORT struct array_list *json_object_get_array(const struct json_object *o
|
||||
|
||||
/** Get the length of a json_object of type json_type_array
|
||||
* @param obj the json_object instance
|
||||
* @returns an int
|
||||
* @returns the length of the array
|
||||
*/
|
||||
JSON_EXPORT size_t json_object_array_length(const struct json_object *obj);
|
||||
|
||||
@@ -1042,7 +1043,7 @@ JSON_EXPORT struct json_object *json_object_new_null(void);
|
||||
*
|
||||
* @param obj1 the first json_object instance
|
||||
* @param obj2 the second json_object instance
|
||||
* @returns whether both objects are equal or not
|
||||
* @returns 1 if both objects are equal, 0 otherwise
|
||||
*/
|
||||
JSON_EXPORT int json_object_equal(struct json_object *obj1, struct json_object *obj2);
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ static int json_pointer_result_get_recursive(struct json_object *obj, char *path
|
||||
struct json_pointer_get_result *res)
|
||||
{
|
||||
struct json_object *parent_obj = obj;
|
||||
size_t idx;
|
||||
size_t idx = 0;
|
||||
char *endp;
|
||||
int rc;
|
||||
|
||||
@@ -231,7 +231,7 @@ int json_pointer_get_internal(struct json_object *obj, const char *path,
|
||||
res->parent = NULL;
|
||||
res->obj = obj;
|
||||
res->key_in_parent = NULL;
|
||||
res->index_in_parent = -1;
|
||||
res->index_in_parent = UINT32_MAX;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -226,7 +226,10 @@ struct json_object *json_tokener_parse_verbose(const char *str, enum json_tokene
|
||||
|
||||
tok = json_tokener_new();
|
||||
if (!tok)
|
||||
{
|
||||
*error = json_tokener_error_memory;
|
||||
return NULL;
|
||||
}
|
||||
obj = json_tokener_parse_ex(tok, str, -1);
|
||||
*error = tok->err;
|
||||
if (tok->err != json_tokener_success
|
||||
@@ -338,9 +341,15 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *
|
||||
#ifdef HAVE_USELOCALE
|
||||
{
|
||||
locale_t duploc = duplocale(oldlocale);
|
||||
if (duploc == NULL && errno == ENOMEM)
|
||||
{
|
||||
tok->err = json_tokener_error_memory;
|
||||
return NULL;
|
||||
}
|
||||
newloc = newlocale(LC_NUMERIC_MASK, "C", duploc);
|
||||
if (newloc == NULL)
|
||||
{
|
||||
tok->err = json_tokener_error_memory;
|
||||
freelocale(duploc);
|
||||
return NULL;
|
||||
}
|
||||
@@ -359,7 +368,10 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *
|
||||
{
|
||||
oldlocale = strdup(tmplocale);
|
||||
if (oldlocale == NULL)
|
||||
{
|
||||
tok->err = json_tokener_error_memory;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
setlocale(LC_NUMERIC, "C");
|
||||
}
|
||||
@@ -666,6 +678,12 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *
|
||||
state = json_tokener_state_string_escape;
|
||||
break;
|
||||
}
|
||||
else if ((tok->flags & JSON_TOKENER_STRICT) && c <= 0x1f)
|
||||
{
|
||||
// Disallow control characters in strict mode
|
||||
tok->err = json_tokener_error_parse_string;
|
||||
goto out;
|
||||
}
|
||||
if (!ADVANCE_CHAR(str, tok) || !PEEK_CHAR(c, tok))
|
||||
{
|
||||
printbuf_memappend_checked(tok->pb, case_start,
|
||||
@@ -1254,7 +1272,11 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *
|
||||
goto redo_char;
|
||||
|
||||
case json_tokener_state_object_value_add:
|
||||
json_object_object_add(current, obj_field_name, obj);
|
||||
if (json_object_object_add(current, obj_field_name, obj) != 0)
|
||||
{
|
||||
tok->err = json_tokener_error_memory;
|
||||
goto out;
|
||||
}
|
||||
free(obj_field_name);
|
||||
obj_field_name = NULL;
|
||||
saved_state = json_tokener_state_object_sep;
|
||||
|
||||
@@ -40,8 +40,8 @@ enum json_tokener_error
|
||||
json_tokener_error_parse_string,
|
||||
json_tokener_error_parse_comment,
|
||||
json_tokener_error_parse_utf8_string,
|
||||
json_tokener_error_memory,
|
||||
json_tokener_error_size
|
||||
json_tokener_error_size, /* A string longer than INT32_MAX was passed as input */
|
||||
json_tokener_error_memory /* Failed to allocate memory */
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -230,7 +230,7 @@ JSON_EXPORT void json_tokener_reset(struct json_tokener *tok);
|
||||
JSON_EXPORT struct json_object *json_tokener_parse(const char *str);
|
||||
|
||||
/**
|
||||
* Parser a json_object out of the string `str`, but if it fails
|
||||
* Parse a json_object out of the string `str`, but if it fails
|
||||
* return the error in `*error`.
|
||||
* @see json_tokener_parse()
|
||||
* @see json_tokener_parse_ex()
|
||||
|
||||
@@ -37,13 +37,13 @@
|
||||
#include <unistd.h>
|
||||
#endif /* HAVE_UNISTD_H */
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <io.h>
|
||||
#include <windows.h>
|
||||
#endif /* defined(WIN32) */
|
||||
#endif /* defined(_WIN32) */
|
||||
|
||||
#if !defined(HAVE_OPEN) && defined(WIN32)
|
||||
#if !defined(HAVE_OPEN) && defined(_WIN32)
|
||||
#define open _open
|
||||
#endif
|
||||
|
||||
|
||||
@@ -229,6 +229,7 @@ static int get_dev_random_seed(int *seed)
|
||||
if ((buf.st_mode & S_IFCHR) == 0)
|
||||
return -1;
|
||||
|
||||
/* coverity[toctou] */
|
||||
int fd = open(dev_random_file, O_RDONLY);
|
||||
if (fd < 0)
|
||||
{
|
||||
@@ -253,7 +254,7 @@ static int get_dev_random_seed(int *seed)
|
||||
|
||||
/* get_cryptgenrandom_seed */
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
|
||||
#define HAVE_CRYPTGENRANDOM 1
|
||||
|
||||
|
||||
@@ -36,6 +36,6 @@ static int json_c_snprintf(char *str, size_t size, const char *format, ...)
|
||||
|
||||
#elif !defined(HAVE_SNPRINTF) /* !HAVE_SNPRINTF */
|
||||
#error snprintf is required but was not found
|
||||
#endif /* !HAVE_SNPRINTF && defined(WIN32) */
|
||||
#endif /* !HAVE_SNPRINTF */
|
||||
|
||||
#endif /* __snprintf_compat_h */
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
cmake_minimum_required(VERSION 3.9)
|
||||
add_executable(test1Formatted test1.c parse_flags.c parse_flags.h)
|
||||
target_compile_definitions(test1Formatted PRIVATE TEST_FORMATTED=1)
|
||||
target_link_libraries(test1Formatted PRIVATE ${PROJECT_NAME})
|
||||
|
||||
@@ -535,7 +535,7 @@ struct incremental_step
|
||||
{"{\"a\":}", -1, 5, json_tokener_error_parse_unexpected, 1, 0},
|
||||
{"{\"a\":1,\"a\":2}", -1, -1, json_tokener_success, 1, 0},
|
||||
{"\"a\":1}", -1, 3, json_tokener_success, 1, 0},
|
||||
{"{\"a\":1", -1, -1, json_tokener_continue, 1, 0},
|
||||
{"{\"a\":1", -1, -1, json_tokener_continue, 1, 0}, //}
|
||||
{"[,]", -1, 1, json_tokener_error_parse_unexpected, 1, 0},
|
||||
{"[,1]", -1, 1, json_tokener_error_parse_unexpected, 1, 0},
|
||||
|
||||
@@ -595,6 +595,44 @@ struct incremental_step
|
||||
{"\x7b\x22\x31\x81\x22\x3a\x31\x7d", -1, 3, json_tokener_error_parse_utf8_string, 1,
|
||||
JSON_TOKENER_VALIDATE_UTF8},
|
||||
|
||||
// Note, current asciiz APIs can't parse \x00, skip it
|
||||
{ "\"0\x01\x02\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" \
|
||||
"\x10\x11\x12\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\"",
|
||||
-1, -1, json_tokener_success, 1, 0 },
|
||||
|
||||
// Test control chars again, this time in strict mode, which should fail
|
||||
{ "\"\x01\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
|
||||
{ "\"\x02\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
|
||||
{ "\"\x03\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
|
||||
{ "\"\x04\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
|
||||
{ "\"\x05\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
|
||||
{ "\"\x06\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
|
||||
{ "\"\x07\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
|
||||
{ "\"\x08\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
|
||||
{ "\"\x09\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
|
||||
{ "\"\x0a\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
|
||||
{ "\"\x0b\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
|
||||
{ "\"\x0c\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
|
||||
{ "\"\x0d\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
|
||||
{ "\"\x0e\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
|
||||
{ "\"\x0f\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
|
||||
{ "\"\x10\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
|
||||
{ "\"\x11\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
|
||||
{ "\"\x12\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
|
||||
{ "\"\x13\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
|
||||
{ "\"\x14\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
|
||||
{ "\"\x15\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
|
||||
{ "\"\x16\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
|
||||
{ "\"\x17\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
|
||||
{ "\"\x18\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
|
||||
{ "\"\x19\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
|
||||
{ "\"\x1a\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
|
||||
{ "\"\x1b\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
|
||||
{ "\"\x1c\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
|
||||
{ "\"\x1d\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
|
||||
{ "\"\x1e\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
|
||||
{ "\"\x1f\"", -1, 1, json_tokener_error_parse_string, 1, JSON_TOKENER_STRICT },
|
||||
|
||||
{NULL, -1, -1, json_tokener_success, 0, 0},
|
||||
};
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
#undef NDEBUG
|
||||
#endif
|
||||
#include "strerror_override.h"
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <io.h>
|
||||
#include <windows.h>
|
||||
#endif /* defined(WIN32) */
|
||||
#endif /* defined(_WIN32) */
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
|
||||
#include "snprintf_compat.h"
|
||||
|
||||
#ifndef WIN32
|
||||
#ifndef _WIN32
|
||||
#include <stdarg.h>
|
||||
#endif /* !defined(WIN32) */
|
||||
#endif /* !defined(_WIN32) */
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -18,10 +18,10 @@
|
||||
/* CAW: compliant version of vasprintf */
|
||||
static int vasprintf(char **buf, const char *fmt, va_list ap)
|
||||
{
|
||||
#ifndef WIN32
|
||||
#ifndef _WIN32
|
||||
static char _T_emptybuffer = '\0';
|
||||
va_list ap2;
|
||||
#endif /* !defined(WIN32) */
|
||||
#endif /* !defined(_WIN32) */
|
||||
int chars;
|
||||
char *b;
|
||||
|
||||
@@ -30,16 +30,16 @@ static int vasprintf(char **buf, const char *fmt, va_list ap)
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
chars = _vscprintf(fmt, ap);
|
||||
#else /* !defined(WIN32) */
|
||||
#else /* !defined(_WIN32) */
|
||||
/* CAW: RAWR! We have to hope to god here that vsnprintf doesn't overwrite
|
||||
* our buffer like on some 64bit sun systems... but hey, it's time to move on
|
||||
*/
|
||||
va_copy(ap2, ap);
|
||||
chars = vsnprintf(&_T_emptybuffer, 0, fmt, ap2);
|
||||
va_end(ap2);
|
||||
#endif /* defined(WIN32) */
|
||||
#endif /* defined(_WIN32) */
|
||||
if (chars < 0 || (size_t)chars + 1 > SIZE_MAX / sizeof(char))
|
||||
{
|
||||
return -1;
|
||||
|
||||
Reference in New Issue
Block a user