Compare commits

..

28 Commits

Author SHA1 Message Date
Max Bruckner 3b0d37faf3 Change name from Configuration to Context 2018-02-03 16:45:10 +01:00
Max Bruckner 464c9b544c cJSON_DuplicateConfiguration 2018-02-03 16:42:58 +01:00
Max Bruckner a0aa2df75a cJSON_ConfigurationChangeParseEnd -> cJSON_ConfigurationGetParseEnd
This is probably a better approach than potentially having a pointer
that points to garbage on the stack and gets written to by cJSON.
2018-02-03 16:42:58 +01:00
Max Bruckner ba81437601 cJSON_CreateConfig: Don't allow configuration, always use default 2018-02-03 16:42:58 +01:00
Max Bruckner d664199036 cJSON_ConfigurationChangeAllowDataAfterJson 2018-02-03 16:42:58 +01:00
Max Bruckner 7e4ac634c6 cJSON_ConfigurationChangeCaseSensitivity 2018-02-03 16:42:57 +01:00
Max Bruckner 1d9d2e8673 cJSON_ConfigurationChangeFormat 2018-02-03 16:42:57 +01:00
Max Bruckner c4c52cfe58 cJSON_ConfigurationChangePrebufferSize 2018-02-03 16:42:57 +01:00
Max Bruckner 0474d4d85f cJSON_ConfigurationChangeParseEnd
Add a pointer to an end position of parsing to the cJSON_Configuration
object. (Essentially like return_parse_end, but as offset instead of
pointer).
2018-02-03 16:42:56 +01:00
Max Bruckner 95d333b5cf cJSON_CreateConfiguration, cJSON_ConfigurationChange{Allocators,Userdata} 2018-02-03 16:42:56 +01:00
Max Bruckner d67ddd5c62 allocation helpers for allocating with a configuration 2018-02-03 16:42:56 +01:00
Max Bruckner 440ba84d08 Add cJSON_Allocators new style allocator struct 2018-02-03 16:42:56 +01:00
Max Bruckner 649af9c2c3 cJSON_Compare: Extract compare with internal_configuration 2018-02-03 16:42:43 +01:00
Max Bruckner 69f8bb7778 default_configuration: Macro for the internal_configuration defaults 2018-02-03 16:40:49 +01:00
Max Bruckner 99ad8cc64b internal_configuration: Add case_sensitive 2018-02-03 16:40:49 +01:00
Max Bruckner 47f4337604 cJSON_ParseWithOpts: Extract pasrse with internal_configuration
Also introduces a allow_data_after_json property in the internal
configuration.
2018-02-03 16:40:49 +01:00
Max Bruckner 772376ed92 cJSON_Delete: Extract delete_item with internal_configuration 2018-02-03 16:40:49 +01:00
Max Bruckner 04137f4ed1 Put buffer_size into internal_configuration 2018-02-03 16:40:48 +01:00
Max Bruckner 479909d0a6 Put format into internal_configuration 2018-02-03 16:40:48 +01:00
Max Bruckner b277cd6a24 Rename internal_hooks -> internal_configuration, cJSON_New_item -> create_item 2018-02-03 16:40:48 +01:00
Max Bruckner e82f32b359 cJSON_Compare: Performance improvement for objects
Check the size to prevent comparing objects equal if they are prefixes
of each other.
2018-02-03 15:56:36 +01:00
Max Bruckner afc246f1d5 parse_value: Check only first character at first
This should improve performance
2018-01-31 10:31:14 +01:00
Max Bruckner 85f76baf0e print_number: Introduce fast path for integers.
Thanks @Tangerino for suggesting this optimisation.
2018-01-29 20:24:42 +01:00
Max Bruckner 3a36ce6d32 Extract helper: double_to_saturated_integer 2018-01-29 20:12:12 +01:00
Max Bruckner deca87b071 is_nan and is_infinity macros 2018-01-20 15:45:21 +01:00
Max Bruckner 5af3271726 CMake: Remove -fsanitize=float-divide-by-zero
This is so that NaN and INFINITY values can be produced.
2018-01-20 15:45:21 +01:00
Max Bruckner 02641037b7 Fix #234: Different argument names between declaration and definition 2018-01-20 14:43:50 +01:00
Max Bruckner 1723a94b53 print: Comment about why the buffer is reallocated 2018-01-19 00:11:07 +01:00
14 changed files with 91 additions and 193 deletions
-2
View File
@@ -14,5 +14,3 @@ libcjson.so.*
libcjson_utils.so.*
*.orig
.vscode
.idea
cmake-build-debug
-24
View File
@@ -1,27 +1,3 @@
1.7.5
=====
Fixes:
------
* Fix a bug in the JSON Patch implementation of `cJSON Utils` (see #251), thanks @bobkocisko.
1.7.4
=====
Fixes:
------
* Fix potential use after free if the `string` parameter to `cJSON_AddItemToObject` is an alias of the `string` property of the object that is added (#248). Thanks @hhallen for reporting.
1.7.3
=====
Fixes:
------
* Fix potential double free, thanks @projectgus for reporting (see #241)
1.7.2
=====
Fixes:
------
* Fix the use of GNUInstallDirs variables and the pkgconfig file. Thanks @zeerd for reporting (see #240)
1.7.1
=====
Fixes:
+18 -12
View File
@@ -7,7 +7,7 @@ include(GNUInstallDirs)
set(PROJECT_VERSION_MAJOR 1)
set(PROJECT_VERSION_MINOR 7)
set(PROJECT_VERSION_PATCH 5)
set(PROJECT_VERSION_PATCH 1)
set(CJSON_VERSION_SO 1)
set(CJSON_UTILS_VERSION_SO 1)
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
@@ -106,6 +106,12 @@ endforeach()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${supported_compiler_flags}")
#variables for pkg-config
set(prefix "${CMAKE_INSTALL_PREFIX}")
set(libdir "${CMAKE_INSTALL_LIBDIR}")
set(version "${PROJECT_VERSION}")
set(includedir "${CMAKE_INSTALL_INCLUDEDIR}")
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(ENABLE_TARGET_EXPORT "Enable exporting of CMake targets. Disable when it causes problems!" ON)
@@ -142,15 +148,15 @@ endif()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/library_config/libcjson.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/libcjson.pc" @ONLY)
install(FILES cJSON.h DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}/cjson")
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcjson.pc" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig")
install(TARGETS "${CJSON_LIB}" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}" EXPORT "${CJSON_LIB}")
install(FILES cJSON.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/cjson")
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcjson.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
install(TARGETS "${CJSON_LIB}" DESTINATION "${CMAKE_INSTALL_LIBDIR}" EXPORT "${CJSON_LIB}")
if (BUILD_SHARED_AND_STATIC_LIBS)
install(TARGETS "${CJSON_LIB}-static" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}")
install(TARGETS "${CJSON_LIB}-static" DESTINATION "${CMAKE_INSTALL_LIBDIR}")
endif()
if(ENABLE_TARGET_EXPORT)
# export library information for CMake projects
install(EXPORT "${CJSON_LIB}" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/cJSON")
install(EXPORT "${CJSON_LIB}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cJSON")
endif()
set_target_properties("${CJSON_LIB}"
@@ -181,15 +187,15 @@ if(ENABLE_CJSON_UTILS)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/library_config/libcjson_utils.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/libcjson_utils.pc" @ONLY)
install(TARGETS "${CJSON_UTILS_LIB}" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}" EXPORT "${CJSON_UTILS_LIB}")
install(TARGETS "${CJSON_UTILS_LIB}" DESTINATION "${CMAKE_INSTALL_LIBDIR}" EXPORT "${CJSON_UTILS_LIB}")
if (BUILD_SHARED_AND_STATIC_LIBS)
install(TARGETS "${CJSON_UTILS_LIB}-static" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}")
install(TARGETS "${CJSON_UTILS_LIB}-static" DESTINATION "${CMAKE_INSTALL_LIBDIR}")
endif()
install(FILES cJSON_Utils.h DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}/cjson")
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcjson_utils.pc" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig")
install(FILES cJSON_Utils.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/cjson")
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcjson_utils.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
if(ENABLE_TARGET_EXPORT)
# export library information for CMake projects
install(EXPORT "${CJSON_UTILS_LIB}" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/cJSON")
install(EXPORT "${CJSON_UTILS_LIB}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cJSON")
endif()
set_target_properties("${CJSON_UTILS_LIB}"
@@ -209,7 +215,7 @@ configure_file(
# Install package config files
install(FILES ${PROJECT_BINARY_DIR}/cJSONConfig.cmake
${PROJECT_BINARY_DIR}/cJSONConfigVersion.cmake
DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/cJSON")
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cJSON")
option(ENABLE_CJSON_TEST "Enable building cJSON test" ON)
if(ENABLE_CJSON_TEST)
-3
View File
@@ -7,7 +7,6 @@ Current Maintainer: [Max Bruckner](https://github.com/FSMaxB)
* [Ajay Bhargav](https://github.com/ajaybhargav)
* [Alper Akcan](https://github.com/alperakcan)
* [Anton Sergeev](https://github.com/anton-sergeev)
* [Bob Kocisko](https://github.com/bobkocisko)
* [Christian Schulze](https://github.com/ChristianSch)
* [Casperinous](https://github.com/Casperinous)
* [Debora Grosse](https://github.com/DeboraG)
@@ -43,5 +42,3 @@ Current Maintainer: [Max Bruckner](https://github.com/FSMaxB)
* [yangfl](https://github.com/yangfl)
And probably more people on [SourceForge](https://sourceforge.net/p/cjson/bugs/search/?q=status%3Aclosed-rejected+or+status%3Aclosed-out-of-date+or+status%3Awont-fix+or+status%3Aclosed-fixed+or+status%3Aclosed&page=0)
Also thanks to all the people who reported bugs and suggested new features.
+1 -1
View File
@@ -8,7 +8,7 @@ CJSON_TEST_SRC = cJSON.c test.c
LDLIBS = -lm
LIBVERSION = 1.7.5
LIBVERSION = 1.7.1
CJSON_SOVERSION = 1
UTILS_SOVERSION = 1
+57 -90
View File
@@ -39,7 +39,9 @@
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <float.h>
#include <limits.h>
#include <ctype.h>
@@ -80,7 +82,7 @@ CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item) {
}
/* This is a safeguard to prevent copy-pasters from using incompatible C and header files */
#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 5)
#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 1)
#error cJSON.h and cJSON.c have different versions. Make sure that both have the same.
#endif
@@ -119,13 +121,12 @@ static int case_insensitive_strcmp(const unsigned char *string1, const unsigned
typedef struct internal_context
{
size_t buffer_size;
size_t end_position;
void *userdata;
cJSON_Allocators allocators;
cJSON_bool format;
cJSON_bool allow_data_after_json;
cJSON_bool case_sensitive;
cJSON_bool duplicate_recursive;
cJSON_Allocators allocators;
void *userdata;
size_t end_position;
} internal_context;
#if defined(_MSC_VER)
@@ -194,17 +195,16 @@ static void deallocate(const internal_context * const context, void *pointer)
#define default_context {\
256, /* default buffer size */\
0, /* default end position */\
NULL, /* no userdata */\
true, /* enable formatting by default */\
true, /* allow data after the JSON by default */\
true, /* case sensitive by default */\
{\
malloc_wrapper,\
free_wrapper,\
realloc_wrapper\
},\
true, /* enable formatting by default */\
true, /* allow data after the JSON by default */\
true, /* case sensitive by default */\
true /* Do cJSON_Duplicate recursively by default */\
NULL, /* no userdata */\
0 /* default end position */\
}
/* this is necessary to assign the default context after initialization */
@@ -340,9 +340,9 @@ typedef struct
} parse_buffer;
/* check if the given size is left to read in a given parse buffer (starting with 1) */
#define can_read(buffer, size) (((buffer)->offset + (size)) <= (buffer)->length)
#define can_read(buffer, size) ((buffer != NULL) && (((buffer)->offset + size) <= (buffer)->length))
/* check if the buffer can be accessed at the given index (starting with 0) */
#define can_access_at_index(buffer, index) (((buffer)->offset + (index)) < (buffer)->length)
#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
#define cannot_access_at_index(buffer, index) (!can_access_at_index(buffer, index))
/* get a pointer to the buffer at the position */
#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
@@ -529,8 +529,8 @@ static void update_offset(printbuffer * const buffer)
buffer->offset += strlen((const char*)buffer_pointer);
}
#define is_nan(number) ((number) != (number))
#define is_infinity(number) (!is_nan(number) && ((number) * 0) != 0)
#define is_nan(number) (number != number)
#define is_infinity(number) (!is_nan(number) && (number * 0) != 0)
/* Render the number nicely from the given item into a string. */
static cJSON_bool print_number(const cJSON * const item, printbuffer * const output_buffer)
@@ -1038,7 +1038,6 @@ static parse_buffer *buffer_skip_whitespace(parse_buffer * const buffer)
buffer->offset++;
}
/* step back if we went over the end */
if (buffer->offset == buffer->length)
{
buffer->offset--;
@@ -1064,7 +1063,7 @@ static parse_buffer *skip_utf8_bom(parse_buffer * const buffer)
}
/* Parse an object - create a new root, and populate. */
static cJSON *parse(const char * const json, const size_t length, internal_context * const context)
static cJSON *parse(const char * const json, internal_context * const context)
{
parse_buffer buffer = { 0, 0, 0, 0, default_context };
cJSON *item = NULL;
@@ -1079,7 +1078,7 @@ static cJSON *parse(const char * const json, const size_t length, internal_conte
}
buffer.content = (const unsigned char*)json;
buffer.length = length;
buffer.length = strlen((const char*)json) + sizeof("");
buffer.offset = 0;
buffer.context = *context;
@@ -1114,6 +1113,7 @@ fail:
delete_item(item, context);
}
if (json != NULL)
{
error local_error;
local_error.json = (const unsigned char*)json;
@@ -1141,13 +1141,8 @@ CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *json, const char **return_
internal_context context = global_context;
cJSON *item = NULL;
if (json == NULL)
{
return NULL;
}
context.allow_data_after_json = !require_null_terminated;
item = parse(json, strlen((const char*)json) + sizeof(""), &context);
item = parse(json, &context);
if (return_parse_end != NULL)
{
@@ -1160,15 +1155,10 @@ CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *json, const char **return_
/* Default options for cJSON_Parse */
CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *json)
{
if (json == NULL)
{
return NULL;
}
return parse(json, strlen((const char*)json) + sizeof(""), &global_context);
return parse(json, &global_context);
}
#define cjson_min(a, b) (((a) < (b)) ? (a) : (b))
#define cjson_min(a, b) ((a < b) ? a : b)
static unsigned char *print(const cJSON * const item, const internal_context * const context)
{
@@ -1407,6 +1397,10 @@ static cJSON_bool print_value(const cJSON * const item, printbuffer * const outp
size_t raw_length = 0;
if (item->valuestring == NULL)
{
if (!output_buffer->noalloc)
{
deallocate(&output_buffer->context, output_buffer->buffer);
}
return false;
}
@@ -2006,37 +2000,32 @@ static void* cast_away_const(const void* string)
static cJSON_bool add_item_to_object(cJSON * const object, const char * const string, cJSON * const item, const internal_context * const context, const cJSON_bool constant_key)
{
char *new_key = NULL;
int new_type = cJSON_Invalid;
if ((object == NULL) || (string == NULL) || (item == NULL))
{
return false;
}
if (constant_key)
{
new_key = (char*)cast_away_const(string);
new_type = item->type | cJSON_StringIsConst;
}
else
{
new_key = (char*)custom_strdup((const unsigned char*)string, context);
if (new_key == NULL)
{
return false;
}
new_type = item->type & ~cJSON_StringIsConst;
}
if (!(item->type & cJSON_StringIsConst) && (item->string != NULL))
{
deallocate(context, item->string);
}
item->string = new_key;
item->type = new_type;
if (constant_key)
{
item->string = (char*)cast_away_const(string);
item->type |= cJSON_StringIsConst;
}
else
{
char *key = (char*)custom_strdup((const unsigned char*)string, context);
if (key == NULL)
{
return false;
}
item->string = key;
item->type &= ~cJSON_StringIsConst;
}
return add_item_to_array(object, item);
}
@@ -2649,60 +2638,56 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char **strings, int count)
return a;
}
static cJSON *duplicate_json(const cJSON *item, const internal_context * const context)
/* Duplication */
CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse)
{
cJSON *newitem = NULL;
cJSON *child = NULL;
cJSON *next = NULL;
cJSON *newchild = NULL;
if (item == NULL)
/* Bail on bad ptr */
if (!item)
{
goto fail;
}
newitem = create_item(context);
if (newitem == NULL)
/* Create new item */
newitem = create_item(&global_context);
if (!newitem)
{
goto fail;
}
/* Copy over all vars */
newitem->type = item->type & (~cJSON_IsReference);
newitem->valueint = item->valueint;
newitem->valuedouble = item->valuedouble;
if (item->valuestring != NULL)
if (item->valuestring)
{
newitem->valuestring = (char*)custom_strdup((unsigned char*)item->valuestring, context);
if (newitem->valuestring == NULL)
newitem->valuestring = (char*)custom_strdup((unsigned char*)item->valuestring, &global_context);
if (!newitem->valuestring)
{
goto fail;
}
}
if (item->string != NULL)
if (item->string)
{
newitem->string = (item->type&cJSON_StringIsConst) ? item->string : (char*)custom_strdup((unsigned char*)item->string, context);
newitem->string = (item->type&cJSON_StringIsConst) ? item->string : (char*)custom_strdup((unsigned char*)item->string, &global_context);
if (!newitem->string)
{
goto fail;
}
}
/* If non-recursive, then we're done! */
if (!context->duplicate_recursive)
if (!recurse)
{
return newitem;
}
/* Walk the ->next chain for the child. */
child = item->child;
while (child != NULL)
{
/* Each item in the ->next chain */
newchild = duplicate_json(child, context);
if (newchild == NULL)
newchild = cJSON_Duplicate(child, true); /* Duplicate (with recurse) each item in the ->next chain */
if (!newchild)
{
goto fail;
}
@@ -2727,19 +2712,12 @@ static cJSON *duplicate_json(const cJSON *item, const internal_context * const c
fail:
if (newitem != NULL)
{
delete_item(newitem, context);
delete_item(newitem, &global_context);
}
return NULL;
}
CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse)
{
internal_context context = global_context;
context.duplicate_recursive = recurse;
return duplicate_json(item, &context);
}
CJSON_PUBLIC(void) cJSON_Minify(char *json)
{
unsigned char *into = (unsigned char*)json;
@@ -3033,17 +3011,6 @@ CJSON_PUBLIC(cJSON_Context) cJSON_AllowDataAfterJson(cJSON_Context context, cJSO
return context;
}
CJSON_PUBLIC(cJSON_Context) cJSON_MakeDuplicateRecursive(cJSON_Context context, cJSON_bool recursive)
{
if (context == NULL)
{
return NULL;
}
((internal_context*)context)->duplicate_recursive = recursive;
return context;
}
static cJSON_bool compare(const cJSON * const a, const cJSON * const b, const internal_context * const context)
{
if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF)) || cJSON_IsInvalid(a))
+1 -3
View File
@@ -31,7 +31,7 @@ extern "C"
/* project version */
#define CJSON_VERSION_MAJOR 1
#define CJSON_VERSION_MINOR 7
#define CJSON_VERSION_PATCH 5
#define CJSON_VERSION_PATCH 1
#include <stddef.h>
@@ -174,8 +174,6 @@ CJSON_PUBLIC(cJSON_Context) cJSON_SetFormat(cJSON_Context context, cJSON_Format
CJSON_PUBLIC(cJSON_Context) cJSON_MakeCaseSensitive(cJSON_Context context, cJSON_bool case_sensitive);
/* Change if data is allowed after the JSON */
CJSON_PUBLIC(cJSON_Context) cJSON_AllowDataAfterJson(cJSON_Context context, cJSON_bool allow_data_after_json);
/* Change if cJSON_Duplicate copies recursively */
CJSON_PUBLIC(cJSON_Context) cJSON_MakeDuplicateRecursive(cJSON_Context context, cJSON_bool recursive);
/* Supply malloc and free functions to cJSON globally */
CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks);
-6
View File
@@ -988,12 +988,6 @@ static int apply_patch(cJSON *object, const cJSON *patch, const cJSON_bool case_
cJSON_AddItemToObject(parent, (char*)child_pointer, value);
value = NULL;
}
else /* parent is not an object */
{
/* Couldn't find object to add to. */
status = 9;
goto cleanup;
}
cleanup:
if (value != NULL)
+2 -2
View File
@@ -2,8 +2,8 @@
set(CJSON_UTILS_FOUND @ENABLE_CJSON_UTILS@)
# The include directories used by cJSON
set(CJSON_INCLUDE_DIRS "@CMAKE_INSTALL_FULL_INCLUDEDIR@")
set(CJSON_INCLUDE_DIR "@CMAKE_INSTALL_FULL_INCLUDEDIR@")
set(CJSON_INCLUDE_DIRS "@prefix@/@includedir@")
set(CJSON_INCLUDE_DIR "@prefix@/@includedir@")
get_filename_component(_dir "${CMAKE_CURRENT_LIST_FILE}" PATH)
+4 -3
View File
@@ -1,8 +1,9 @@
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
prefix=@prefix@
libdir=${prefix}/@libdir@
includedir=${prefix}/@includedir@
Name: libcjson
Version: @PROJECT_VERSION@
Version: @version@
Description: Ultralightweight JSON parser in ANSI C
URL: https://github.com/DaveGamble/cJSON
Libs: -L${libdir} -lcjson
+4 -3
View File
@@ -1,8 +1,9 @@
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
prefix=@prefix@
libdir=${prefix}/@libdir@
includedir=${prefix}/@includedir@
Name: libcjson_utils
Version: @PROJECT_VERSION@
Version: @version@
Description: An implementation of JSON Pointer, Patch and Merge Patch based on cJSON.
URL: https://github.com/DaveGamble/cJSON
Libs: -L${libdir} -lcjson_utils
-14
View File
@@ -39,7 +39,6 @@ static void create_context_should_create_a_context(void)
TEST_ASSERT_TRUE_MESSAGE(context->case_sensitive, "case_sensitive has an incorrect value.");
TEST_ASSERT_TRUE_MESSAGE(context->allow_data_after_json, "allow_data_after_json has an incorrect value.");
TEST_ASSERT_NULL_MESSAGE(context->userdata, "Userdata should be NULL");
TEST_ASSERT_TRUE_MESSAGE(context->duplicate_recursive, "Duplicating is not recursive.");
TEST_ASSERT_TRUE_MESSAGE(malloc_wrapper == context->allocators.allocate, "Wrong malloc.");
TEST_ASSERT_TRUE_MESSAGE(realloc_wrapper == context->allocators.reallocate, "Wrong realloc.");
TEST_ASSERT_TRUE_MESSAGE(free_wrapper == context->allocators.deallocate, "Wrong free.");
@@ -241,18 +240,6 @@ static void allow_data_after_json_should_change_allow_data_after_json(void)
free(context);
}
static void make_duplicate_recursive_should_make_duplicate_recursive(void)
{
internal_context *context = (internal_context*)cJSON_CreateContext(NULL, NULL);
TEST_ASSERT_NOT_NULL(context);
context = (internal_context*)cJSON_MakeDuplicateRecursive(context, false);
TEST_ASSERT_NOT_NULL(context);
TEST_ASSERT_FALSE_MESSAGE(context->duplicate_recursive, "Duplicating is not set correctly.");
free(context);
}
int main(void)
{
UNITY_BEGIN();
@@ -272,7 +259,6 @@ int main(void)
RUN_TEST(set_format_should_set_format);
RUN_TEST(make_case_sensitive_should_change_case_sensitivity);
RUN_TEST(allow_data_after_json_should_change_allow_data_after_json);
RUN_TEST(make_duplicate_recursive_should_make_duplicate_recursive);
return UNITY_END();
}
@@ -80,12 +80,5 @@
"doc": { "foo": ["bar"] },
"patch": [ { "op": "add", "path": "/foo/-", "value": ["abc", "def"] }],
"expected": {"foo": ["bar", ["abc", "def"]] }
},
{
"comment": "15",
"doc": {"foo": {"bar": 1}},
"patch": [{"op": "add", "path": "/foo/bar/baz", "value": "5"}],
"error": "attempting to add to subfield of non-object"
}
}
]
+3 -22
View File
@@ -10,7 +10,8 @@
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
@@ -419,7 +420,7 @@ static void *failing_realloc(void *pointer, size_t size, void *userdata)
static void ensure_should_fail_on_failed_realloc(void)
{
printbuffer buffer = {NULL, 10, 0, 0, false, {256, 0, NULL, {malloc_wrapper, free_wrapper, failing_realloc}, false, true, true, true} };
printbuffer buffer = {NULL, 10, 0, 0, false, {256, false, true, true, {malloc_wrapper, free_wrapper, failing_realloc}, NULL, 0 } };
buffer.context.userdata = &buffer;
buffer.buffer = (unsigned char*)malloc(100);
TEST_ASSERT_NOT_NULL(buffer.buffer);
@@ -509,25 +510,6 @@ static void cjson_create_array_reference_should_create_an_array_reference(void)
cJSON_Delete(number_reference);
}
static void cjson_add_item_to_object_should_not_use_after_free_when_string_is_aliased(void)
{
cJSON *object = cJSON_CreateObject();
cJSON *number = cJSON_CreateNumber(42);
char *name = (char*)custom_strdup((const unsigned char*)"number", &global_context);
TEST_ASSERT_NOT_NULL(object);
TEST_ASSERT_NOT_NULL(number);
TEST_ASSERT_NOT_NULL(name);
number->string = name;
/* The following should not have a use after free
* that would show up in valgrind or with AddressSanitizer */
cJSON_AddItemToObject(object, number->string, number);
cJSON_Delete(object);
}
static void is_nan_should_detect_nan(void)
{
double nan = 0.0/0.0;
@@ -568,7 +550,6 @@ int main(void)
RUN_TEST(cjson_create_string_reference_should_create_a_string_reference);
RUN_TEST(cjson_create_object_reference_should_create_an_object_reference);
RUN_TEST(cjson_create_array_reference_should_create_an_array_reference);
RUN_TEST(cjson_add_item_to_object_should_not_use_after_free_when_string_is_aliased);
RUN_TEST(is_nan_should_detect_nan);
RUN_TEST(is_infinity_should_detect_infinity);