Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ae80f5ef57 |
@@ -23,6 +23,6 @@ addons:
|
||||
script:
|
||||
- mkdir build
|
||||
- cd build
|
||||
- cmake .. -DENABLE_CJSON_UTILS=On -DENABLE_VALGRIND="${VALGRIND}" -DENABLE_SAFE_STACK="${VALGRIND}" -DENABLE_SANITIZERS="${SANITIZERS}"
|
||||
- cmake .. -DENABLE_CJSON_UTILS=On -DENABLE_VALGRIND="${VALGRIND}" -DENABLE_SANITIZERS="${SANITIZERS}"
|
||||
- make
|
||||
- make test CTEST_OUTPUT_ON_FAILURE=On
|
||||
|
||||
@@ -73,16 +73,6 @@ if (ENABLE_SANITIZERS)
|
||||
)
|
||||
endif()
|
||||
|
||||
option(ENABLE_SAFE_STACK "Enables the SafeStack instrumentation pass by the Code Pointer Integrity Project" OFF)
|
||||
if (ENABLE_SAFE_STACK)
|
||||
if (ENABLE_SANITIZERS)
|
||||
message(FATAL_ERROR "ENABLE_SAFE_STACK cannot be used in combination with ENABLE_SANITIZERS")
|
||||
endif()
|
||||
list(APPEND custom_compiler_flags
|
||||
-fsanitize=safe-stack
|
||||
)
|
||||
endif()
|
||||
|
||||
option(ENABLE_PUBLIC_SYMBOLS "Export library symbols." On)
|
||||
if (ENABLE_PUBLIC_SYMBOLS)
|
||||
list(APPEND custom_compiler_flags -fvisibility=hidden)
|
||||
|
||||
@@ -88,7 +88,6 @@ You can change the build process with a list of different options that you can p
|
||||
* `-DENABLE_CUSTOM_COMPILER_FLAGS=On`: Enable custom compiler flags (currently for Clang, GCC and MSVC). Turn off if it makes problems. (on by default)
|
||||
* `-DENABLE_VALGRIND=On`: Run tests with [valgrind](http://valgrind.org). (off by default)
|
||||
* `-DENABLE_SANITIZERS=On`: Compile cJSON with [AddressSanitizer](https://github.com/google/sanitizers/wiki/AddressSanitizer) and [UndefinedBehaviorSanitizer](https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html) enabled (if possible). (off by default)
|
||||
* `-DENABLE_SAFE_STACK`: Enable the [SafeStack](https://clang.llvm.org/docs/SafeStack.html) instrumentation pass. Currently only works with the Clang compiler. (off by default)
|
||||
* `-DBUILD_SHARED_LIBS=On`: Build the shared libraries. (on by default)
|
||||
* `-DBUILD_SHARED_AND_STATIC_LIBS=On`: Build both shared and static libraries. (off by default)
|
||||
* `-DCMAKE_INSTALL_PREFIX=/usr`: Set a prefix for the installation.
|
||||
|
||||
82
appveyor.yml
82
appveyor.yml
@@ -1,82 +0,0 @@
|
||||
os: Visual Studio 2015
|
||||
|
||||
# ENABLE_CUSTOM_COMPILER_FLAGS - on by default
|
||||
# ENABLE_SANITIZERS - off by default
|
||||
# ENABLE_PUBLIC_SYMBOLS - on by default
|
||||
# BUILD_SHARED_LIBS - on by default
|
||||
# ENABLE_TARGET_EXPORT - on by default
|
||||
# ENABLE_CJSON_UTILS - off by default
|
||||
# ENABLE_CJSON_TEST -on by default
|
||||
# ENABLE_VALGRIND - off by default
|
||||
# ENABLE_FUZZING - off by default
|
||||
|
||||
environment:
|
||||
matrix:
|
||||
- GENERATOR: "Visual Studio 14 2015"
|
||||
BUILD_SHARED_LIBS: ON
|
||||
ENABLE_CJSON_TEST: OFF
|
||||
ENABLE_CJSON_UTILS: ON
|
||||
|
||||
- GENERATOR: "Visual Studio 14 2015"
|
||||
BUILD_SHARED_LIBS: OFF
|
||||
ENABLE_CJSON_TEST: OFF
|
||||
ENABLE_CJSON_UTILS: ON
|
||||
|
||||
- GENERATOR: "Visual Studio 12 2013"
|
||||
BUILD_SHARED_LIBS: ON
|
||||
ENABLE_CJSON_TEST: OFF
|
||||
ENABLE_CJSON_UTILS: ON
|
||||
|
||||
- GENERATOR: "Visual Studio 12 2013"
|
||||
BUILD_SHARED_LIBS: OFF
|
||||
ENABLE_CJSON_TEST: OFF
|
||||
ENABLE_CJSON_UTILS: ON
|
||||
|
||||
- GENERATOR: "Visual Studio 11 2012"
|
||||
BUILD_SHARED_LIBS: ON
|
||||
ENABLE_CJSON_TEST: OFF
|
||||
ENABLE_CJSON_UTILS: ON
|
||||
|
||||
- GENERATOR: "Visual Studio 11 2012"
|
||||
BUILD_SHARED_LIBS: OFF
|
||||
ENABLE_CJSON_TEST: OFF
|
||||
ENABLE_CJSON_UTILS: ON
|
||||
|
||||
- GENERATOR: "Visual Studio 10 2010"
|
||||
BUILD_SHARED_LIBS: ON
|
||||
ENABLE_CJSON_TEST: OFF
|
||||
ENABLE_CJSON_UTILS: ON
|
||||
|
||||
- GENERATOR: "Visual Studio 10 2010"
|
||||
BUILD_SHARED_LIBS: OFF
|
||||
ENABLE_CJSON_TEST: OFF
|
||||
ENABLE_CJSON_UTILS: ON
|
||||
|
||||
- GENERATOR: "Visual Studio 9 2008"
|
||||
BUILD_SHARED_LIBS: ON
|
||||
ENABLE_CJSON_TEST: OFF
|
||||
ENABLE_CJSON_UTILS: ON
|
||||
|
||||
- GENERATOR: "Visual Studio 9 2008"
|
||||
BUILD_SHARED_LIBS: OFF
|
||||
ENABLE_CJSON_TEST: OFF
|
||||
ENABLE_CJSON_UTILS: ON
|
||||
|
||||
|
||||
platform:
|
||||
- x86
|
||||
- x64
|
||||
|
||||
configuration:
|
||||
- Release
|
||||
|
||||
|
||||
build_script:
|
||||
- ps: if($env:PLATFORM -eq "x64") { $env:CMAKE_GEN_SUFFIX=" Win64" }
|
||||
- cmake "-G%GENERATOR%%CMAKE_GEN_SUFFIX%" -DBUILD_SHARED_LIBS=%BUILD_SHARED_LIBS% -DENABLE_CJSON_TEST=%ENABLE_CJSON_TEST% -H. -Bbuild
|
||||
- cmake --build build --config "%CONFIGURATION%"
|
||||
|
||||
|
||||
on_failure:
|
||||
- ps: if(Test-Path builds/CMakeFiles/CMakeOutput.log) { cat builds/CMakeFiles/CMakeOutput.log }
|
||||
- ps: if(Test-Path builds/CMakeFiles/CMakeError.log) { cat builds/CMakeFiles/CMakeError.log }
|
||||
19
cJSON.c
19
cJSON.c
@@ -958,22 +958,6 @@ static parse_buffer *buffer_skip_whitespace(parse_buffer * const buffer)
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/* skip the UTF-8 BOM (byte order mark) if it is at the beginning of a buffer */
|
||||
static parse_buffer *skip_utf8_bom(parse_buffer * const buffer)
|
||||
{
|
||||
if ((buffer == NULL) || (buffer->content == NULL) || (buffer->offset != 0))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (can_access_at_index(buffer, 4) && (strncmp((const char*)buffer_at_offset(buffer), "\xEF\xBB\xBF", 3) == 0))
|
||||
{
|
||||
buffer->offset += 3;
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/* Parse an object - create a new root, and populate. */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated)
|
||||
{
|
||||
@@ -1000,7 +984,7 @@ CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!parse_value(item, buffer_skip_whitespace(skip_utf8_bom(&buffer))))
|
||||
if (!parse_value(item, buffer_skip_whitespace(&buffer)))
|
||||
{
|
||||
/* parse failure. ep is set. */
|
||||
goto fail;
|
||||
@@ -1238,6 +1222,7 @@ static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buf
|
||||
return parse_object(item, input_buffer);
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
58
meson.build
Normal file
58
meson.build
Normal file
@@ -0,0 +1,58 @@
|
||||
project('cJSON', 'c', default_options: ['c_std=c89'])
|
||||
version = '1.6.0'
|
||||
soversion = '0'
|
||||
|
||||
compiler = meson.get_compiler('c')
|
||||
|
||||
compiler_flags = []
|
||||
|
||||
if (compiler.get_id() == 'clang') or (compiler.get_id() == 'gcc')
|
||||
compiler_flags += [
|
||||
'-pedantic',
|
||||
'-Wall',
|
||||
'-Wextra',
|
||||
'-Werror',
|
||||
'-Wstrict-prototypes',
|
||||
'-Wwrite-strings',
|
||||
'-Wshadow',
|
||||
'-Winit-self',
|
||||
'-Wcast-align',
|
||||
'-Wformat=2',
|
||||
'-Wmissing-prototypes',
|
||||
'-Wstrict-overflow=2',
|
||||
'-Wcast-qual',
|
||||
'-Wundef',
|
||||
'-Wswitch-default',
|
||||
'-Wconversion',
|
||||
'-Wc++-compat',
|
||||
'-fstack-protector-strong',
|
||||
'-Wcomma',
|
||||
'-Wdouble-promotion',
|
||||
'-Wparentheses',
|
||||
'-Wformat-overflow',
|
||||
'-Wunused-macros',
|
||||
'-Wmissing-variable-declarations',
|
||||
'-Wused-but-marked-unused',
|
||||
'-Wswitch-enum'
|
||||
]
|
||||
endif
|
||||
|
||||
foreach flag : compiler_flags
|
||||
if compiler.has_argument(flag)
|
||||
add_project_arguments(flag, language: 'c')
|
||||
endif
|
||||
endforeach
|
||||
|
||||
math = compiler.find_library('m', required: false)
|
||||
|
||||
cjson = shared_library('cjson', 'cJSON.c', dependencies: math, version: version, soversion: soversion, install: true)
|
||||
if get_option('enable_cjson_utils')
|
||||
cjson_utils = shared_library('cjson_utils', 'cJSON_Utils.c', link_with: cjson, version: version, soversion: soversion, install: true)
|
||||
endif
|
||||
|
||||
if get_option('enable_cjson_tests')
|
||||
cjson_test = executable('cjson_test', 'test.c', link_with: cjson)
|
||||
test('cjson_test', cjson_test)
|
||||
endif
|
||||
|
||||
subdir('tests')
|
||||
2
meson_options.txt
Normal file
2
meson_options.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
option('enable_cjson_utils', type: 'boolean', value: true)
|
||||
option('enable_cjson_tests', type: 'boolean', value: true)
|
||||
58
tests/meson.build
Normal file
58
tests/meson.build
Normal file
@@ -0,0 +1,58 @@
|
||||
if get_option('enable_cjson_tests')
|
||||
unity_flags = []
|
||||
|
||||
if (compiler.get_id() == 'clang') or (compiler.get_id() == 'gcc')
|
||||
unity_flags += [
|
||||
'-Wno-switch-enum',
|
||||
'-Wno-error',
|
||||
'-fvisibility=default',
|
||||
'-fno-sanitize=float-divide-by-zero'
|
||||
]
|
||||
endif
|
||||
|
||||
unity_c_args = []
|
||||
foreach flag : unity_flags
|
||||
if compiler.has_argument(flag)
|
||||
unity_c_args += flag
|
||||
endif
|
||||
endforeach
|
||||
|
||||
unity = library('unity', 'unity/src/unity.c', c_args: unity_c_args)
|
||||
common = library('test_common', 'common.c')
|
||||
|
||||
cjson_tests = [
|
||||
'parse_examples',
|
||||
'parse_number',
|
||||
'parse_hex4',
|
||||
'parse_string',
|
||||
'parse_array',
|
||||
'parse_object',
|
||||
'parse_value',
|
||||
'print_string',
|
||||
'print_number',
|
||||
'print_array',
|
||||
'print_object',
|
||||
'print_value',
|
||||
'misc_tests',
|
||||
'parse_with_opts',
|
||||
'compare_tests'
|
||||
]
|
||||
|
||||
foreach cjson_test : cjson_tests
|
||||
exe = executable(cjson_test, cjson_test + '.c', link_with: [common, cjson, unity])
|
||||
test(cjson_test, exe, workdir: meson.current_source_dir())
|
||||
endforeach
|
||||
|
||||
if get_option('enable_cjson_utils')
|
||||
cjson_utils_tests = [
|
||||
'json_patch_tests',
|
||||
'old_utils_tests',
|
||||
'misc_utils_tests'
|
||||
]
|
||||
|
||||
foreach cjson_utils_test : cjson_utils_tests
|
||||
exe = executable(cjson_utils_test, cjson_utils_test + '.c', link_with: [common, cjson_utils, unity, cjson])
|
||||
test(cjson_utils_test, exe, workdir: meson.current_source_dir())
|
||||
endforeach
|
||||
endif
|
||||
endif
|
||||
@@ -410,30 +410,6 @@ static void cjson_functions_shouldnt_crash_with_null_pointers(void)
|
||||
cJSON_Delete(item);
|
||||
}
|
||||
|
||||
static void skip_utf8_bom_should_skip_bom(void)
|
||||
{
|
||||
const unsigned char string[] = "\xEF\xBB\xBF{}";
|
||||
parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } };
|
||||
buffer.content = string;
|
||||
buffer.length = sizeof(string);
|
||||
buffer.hooks = global_hooks;
|
||||
|
||||
TEST_ASSERT_TRUE(skip_utf8_bom(&buffer) == &buffer);
|
||||
TEST_ASSERT_EQUAL_UINT(3U, (unsigned int)buffer.offset);
|
||||
}
|
||||
|
||||
static void skip_utf8_bom_should_not_skip_bom_if_not_at_beginning(void)
|
||||
{
|
||||
const unsigned char string[] = " \xEF\xBB\xBF{}";
|
||||
parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } };
|
||||
buffer.content = string;
|
||||
buffer.length = sizeof(string);
|
||||
buffer.hooks = global_hooks;
|
||||
buffer.offset = 1;
|
||||
|
||||
TEST_ASSERT_NULL(skip_utf8_bom(&buffer));
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
UNITY_BEGIN();
|
||||
@@ -449,8 +425,6 @@ int main(void)
|
||||
RUN_TEST(cjson_replace_item_via_pointer_should_replace_items);
|
||||
RUN_TEST(cjson_replace_item_in_object_should_preserve_name);
|
||||
RUN_TEST(cjson_functions_shouldnt_crash_with_null_pointers);
|
||||
RUN_TEST(skip_utf8_bom_should_skip_bom);
|
||||
RUN_TEST(skip_utf8_bom_should_not_skip_bom_if_not_at_beginning);
|
||||
|
||||
return UNITY_END();
|
||||
}
|
||||
|
||||
@@ -69,22 +69,6 @@ static void parse_with_opts_should_return_parse_end(void)
|
||||
cJSON_Delete(item);
|
||||
}
|
||||
|
||||
static void parse_with_opts_should_parse_utf8_bom(void)
|
||||
{
|
||||
cJSON *with_bom = NULL;
|
||||
cJSON *without_bom = NULL;
|
||||
|
||||
with_bom = cJSON_ParseWithOpts("\xEF\xBB\xBF{}", NULL, true);
|
||||
TEST_ASSERT_NOT_NULL(with_bom);
|
||||
without_bom = cJSON_ParseWithOpts("{}", NULL, true);
|
||||
TEST_ASSERT_NOT_NULL(with_bom);
|
||||
|
||||
TEST_ASSERT_TRUE(cJSON_Compare(with_bom, without_bom, true));
|
||||
|
||||
cJSON_Delete(with_bom);
|
||||
cJSON_Delete(without_bom);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
UNITY_BEGIN();
|
||||
@@ -93,7 +77,6 @@ int main(void)
|
||||
RUN_TEST(parse_with_opts_should_handle_empty_strings);
|
||||
RUN_TEST(parse_with_opts_should_require_null_if_requested);
|
||||
RUN_TEST(parse_with_opts_should_return_parse_end);
|
||||
RUN_TEST(parse_with_opts_should_parse_utf8_bom);
|
||||
|
||||
return UNITY_END();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user