Compare commits

...

7 Commits

Author SHA1 Message Date
Max Bruckner
27caa364b0 Release version 1.7.2 2018-02-06 11:38:41 +01:00
Max Bruckner
f47271f455 Fix pkgconfig and installation. Thanks @zeerd for reporting
CMAKE_INSTALL_FULL_... needs to be used.
2018-02-06 11:24:03 +01:00
Max Bruckner
7cc52f6035 Merge pull request #231 from DaveGamble/fixes
Release Version 1.7.1
2018-01-09 22:34:48 +01:00
Max Bruckner
b60b5d3744 Update version to 1.7.1 2018-01-09 21:59:42 +01:00
Max Bruckner
4d84acf926 print_number: fix Off-By-One error
Thanks @liuyunbin for reporting this in #230
2018-01-09 21:40:55 +01:00
Max Bruckner
28d4410f42 print: fix: realloc was allocating too much memory
Thanks @liuyunbin for reporting this in #230
2018-01-09 20:53:33 +01:00
Max Bruckner
f33fa95f3d print: Fix default buffer size in printbuffer
Thanks @liuyunbin for reporting this in #230
2018-01-09 20:49:03 +01:00
8 changed files with 41 additions and 34 deletions

View File

@@ -1,3 +1,16 @@
1.7.2
=====
Fixes:
------
* Fix the use of GNUInstallDirs variables and the pkgconfig file. Thanks @zeerd for reporting (see #240)
1.7.1
=====
Fixes:
------
* Fixed an Off-By-One error that could lead to an out of bounds write. Thanks @liuyunbin for reporting (see #230)
* Fixed two errors with buffered printing. Thanks @liuyunbin for reporting (see #230)
1.7.0 1.7.0
===== =====
Features: Features:

View File

@@ -7,7 +7,7 @@ include(GNUInstallDirs)
set(PROJECT_VERSION_MAJOR 1) set(PROJECT_VERSION_MAJOR 1)
set(PROJECT_VERSION_MINOR 7) set(PROJECT_VERSION_MINOR 7)
set(PROJECT_VERSION_PATCH 0) set(PROJECT_VERSION_PATCH 2)
set(CJSON_VERSION_SO 1) set(CJSON_VERSION_SO 1)
set(CJSON_UTILS_VERSION_SO 1) set(CJSON_UTILS_VERSION_SO 1)
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}") set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
@@ -107,12 +107,6 @@ endforeach()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${supported_compiler_flags}") 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(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(ENABLE_TARGET_EXPORT "Enable exporting of CMake targets. Disable when it causes problems!" ON) option(ENABLE_TARGET_EXPORT "Enable exporting of CMake targets. Disable when it causes problems!" ON)
@@ -149,15 +143,15 @@ endif()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/library_config/libcjson.pc.in" configure_file("${CMAKE_CURRENT_SOURCE_DIR}/library_config/libcjson.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/libcjson.pc" @ONLY) "${CMAKE_CURRENT_BINARY_DIR}/libcjson.pc" @ONLY)
install(FILES cJSON.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/cjson") install(FILES cJSON.h DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}/cjson")
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcjson.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcjson.pc" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig")
install(TARGETS "${CJSON_LIB}" DESTINATION "${CMAKE_INSTALL_LIBDIR}" EXPORT "${CJSON_LIB}") install(TARGETS "${CJSON_LIB}" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}" EXPORT "${CJSON_LIB}")
if (BUILD_SHARED_AND_STATIC_LIBS) if (BUILD_SHARED_AND_STATIC_LIBS)
install(TARGETS "${CJSON_LIB}-static" DESTINATION "${CMAKE_INSTALL_LIBDIR}") install(TARGETS "${CJSON_LIB}-static" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}")
endif() endif()
if(ENABLE_TARGET_EXPORT) if(ENABLE_TARGET_EXPORT)
# export library information for CMake projects # export library information for CMake projects
install(EXPORT "${CJSON_LIB}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cJSON") install(EXPORT "${CJSON_LIB}" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/cJSON")
endif() endif()
set_target_properties("${CJSON_LIB}" set_target_properties("${CJSON_LIB}"
@@ -188,15 +182,15 @@ if(ENABLE_CJSON_UTILS)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/library_config/libcjson_utils.pc.in" configure_file("${CMAKE_CURRENT_SOURCE_DIR}/library_config/libcjson_utils.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/libcjson_utils.pc" @ONLY) "${CMAKE_CURRENT_BINARY_DIR}/libcjson_utils.pc" @ONLY)
install(TARGETS "${CJSON_UTILS_LIB}" DESTINATION "${CMAKE_INSTALL_LIBDIR}" EXPORT "${CJSON_UTILS_LIB}") install(TARGETS "${CJSON_UTILS_LIB}" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}" EXPORT "${CJSON_UTILS_LIB}")
if (BUILD_SHARED_AND_STATIC_LIBS) if (BUILD_SHARED_AND_STATIC_LIBS)
install(TARGETS "${CJSON_UTILS_LIB}-static" DESTINATION "${CMAKE_INSTALL_LIBDIR}") install(TARGETS "${CJSON_UTILS_LIB}-static" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}")
endif() endif()
install(FILES cJSON_Utils.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/cjson") install(FILES cJSON_Utils.h DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}/cjson")
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcjson_utils.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libcjson_utils.pc" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig")
if(ENABLE_TARGET_EXPORT) if(ENABLE_TARGET_EXPORT)
# export library information for CMake projects # export library information for CMake projects
install(EXPORT "${CJSON_UTILS_LIB}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cJSON") install(EXPORT "${CJSON_UTILS_LIB}" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/cJSON")
endif() endif()
set_target_properties("${CJSON_UTILS_LIB}" set_target_properties("${CJSON_UTILS_LIB}"
@@ -216,7 +210,7 @@ configure_file(
# Install package config files # Install package config files
install(FILES ${PROJECT_BINARY_DIR}/cJSONConfig.cmake install(FILES ${PROJECT_BINARY_DIR}/cJSONConfig.cmake
${PROJECT_BINARY_DIR}/cJSONConfigVersion.cmake ${PROJECT_BINARY_DIR}/cJSONConfigVersion.cmake
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cJSON") DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/cJSON")
option(ENABLE_CJSON_TEST "Enable building cJSON test" ON) option(ENABLE_CJSON_TEST "Enable building cJSON test" ON)
if(ENABLE_CJSON_TEST) if(ENABLE_CJSON_TEST)

View File

@@ -8,7 +8,7 @@ CJSON_TEST_SRC = cJSON.c test.c
LDLIBS = -lm LDLIBS = -lm
LIBVERSION = 1.7.0 LIBVERSION = 1.7.2
CJSON_SOVERSION = 1 CJSON_SOVERSION = 1
UTILS_SOVERSION = 1 UTILS_SOVERSION = 1

10
cJSON.c
View File

@@ -82,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 */ /* 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 != 0) #if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 2)
#error cJSON.h and cJSON.c have different versions. Make sure that both have the same. #error cJSON.h and cJSON.c have different versions. Make sure that both have the same.
#endif #endif
@@ -512,7 +512,7 @@ static cJSON_bool print_number(const cJSON * const item, printbuffer * const out
} }
/* reserve appropriate space in the output */ /* reserve appropriate space in the output */
output_pointer = ensure(output_buffer, (size_t)length); output_pointer = ensure(output_buffer, (size_t)length + sizeof(""));
if (output_pointer == NULL) if (output_pointer == NULL)
{ {
return false; return false;
@@ -1087,13 +1087,15 @@ CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value)
static unsigned char *print(const cJSON * const item, cJSON_bool format, const internal_hooks * const hooks) static unsigned char *print(const cJSON * const item, cJSON_bool format, const internal_hooks * const hooks)
{ {
static const size_t default_buffer_size = 256;
printbuffer buffer[1]; printbuffer buffer[1];
unsigned char *printed = NULL; unsigned char *printed = NULL;
memset(buffer, 0, sizeof(buffer)); memset(buffer, 0, sizeof(buffer));
/* create buffer */ /* create buffer */
buffer->buffer = (unsigned char*) hooks->allocate(256); buffer->buffer = (unsigned char*) hooks->allocate(default_buffer_size);
buffer->length = default_buffer_size;
buffer->format = format; buffer->format = format;
buffer->hooks = *hooks; buffer->hooks = *hooks;
if (buffer->buffer == NULL) if (buffer->buffer == NULL)
@@ -1111,7 +1113,7 @@ static unsigned char *print(const cJSON * const item, cJSON_bool format, const i
/* check if reallocate is available */ /* check if reallocate is available */
if (hooks->reallocate != NULL) if (hooks->reallocate != NULL)
{ {
printed = (unsigned char*) hooks->reallocate(buffer->buffer, buffer->length); printed = (unsigned char*) hooks->reallocate(buffer->buffer, buffer->offset + 1);
buffer->buffer = NULL; buffer->buffer = NULL;
if (printed == NULL) { if (printed == NULL) {
goto fail; goto fail;

View File

@@ -31,7 +31,7 @@ extern "C"
/* project version */ /* project version */
#define CJSON_VERSION_MAJOR 1 #define CJSON_VERSION_MAJOR 1
#define CJSON_VERSION_MINOR 7 #define CJSON_VERSION_MINOR 7
#define CJSON_VERSION_PATCH 0 #define CJSON_VERSION_PATCH 2
#include <stddef.h> #include <stddef.h>

View File

@@ -2,8 +2,8 @@
set(CJSON_UTILS_FOUND @ENABLE_CJSON_UTILS@) set(CJSON_UTILS_FOUND @ENABLE_CJSON_UTILS@)
# The include directories used by cJSON # The include directories used by cJSON
set(CJSON_INCLUDE_DIRS "@prefix@/@includedir@") set(CJSON_INCLUDE_DIRS "@CMAKE_INSTALL_FULL_INCLUDEDIR@")
set(CJSON_INCLUDE_DIR "@prefix@/@includedir@") set(CJSON_INCLUDE_DIR "@CMAKE_INSTALL_FULL_INCLUDEDIR@")
get_filename_component(_dir "${CMAKE_CURRENT_LIST_FILE}" PATH) get_filename_component(_dir "${CMAKE_CURRENT_LIST_FILE}" PATH)

View File

@@ -1,9 +1,8 @@
prefix=@prefix@ libdir=@CMAKE_INSTALL_FULL_LIBDIR@
libdir=${prefix}/@libdir@ includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
includedir=${prefix}/@includedir@
Name: libcjson Name: libcjson
Version: @version@ Version: @PROJECT_VERSION@
Description: Ultralightweight JSON parser in ANSI C Description: Ultralightweight JSON parser in ANSI C
URL: https://github.com/DaveGamble/cJSON URL: https://github.com/DaveGamble/cJSON
Libs: -L${libdir} -lcjson Libs: -L${libdir} -lcjson

View File

@@ -1,9 +1,8 @@
prefix=@prefix@ libdir=@CMAKE_INSTALL_FULL_LIBDIR@
libdir=${prefix}/@libdir@ includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
includedir=${prefix}/@includedir@
Name: libcjson_utils Name: libcjson_utils
Version: @version@ Version: @PROJECT_VERSION@
Description: An implementation of JSON Pointer, Patch and Merge Patch based on cJSON. Description: An implementation of JSON Pointer, Patch and Merge Patch based on cJSON.
URL: https://github.com/DaveGamble/cJSON URL: https://github.com/DaveGamble/cJSON
Libs: -L${libdir} -lcjson_utils Libs: -L${libdir} -lcjson_utils