cJSON

mirror of Dave's cJSON
git clone git://git.thc420.xyz/cJSON
Log | Files | Refs | README | LICENSE

commit 1f0ad823c96d0874393cdc51e14be45d02aa96c6
parent 4703f01cf411bd3e3f97c2487deac8a1ef92ac8d
Author: Max Bruckner <max@maxbruckner.de>
Date:   Mon, 28 Nov 2016 00:58:45 +0700

Merge pull request #75 from gatzka/feature/enhance_gcc_checks_v2

Enhance gcc checks v2
Diffstat:
MCMakeLists.txt | 2+-
MMakefile | 4++--
Mtest.c | 8+++++---
Mtest_utils.c | 22+++++++++++-----------
4 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt @@ -15,7 +15,7 @@ set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT option(ENABLE_CUSTOM_COMPILER_FLAGS "Enables custom compiler flags for Clang and GCC" ON) if (ENABLE_CUSTOM_COMPILER_FLAGS) if(("${CMAKE_C_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c89 -pedantic -Wall -Wextra -Werror -Wstrict-prototypes -Wwrite-strings") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c89 -pedantic -Wall -Wextra -Werror -Wstrict-prototypes -Wwrite-strings -Wshadow -Winit-self -Wcast-align -Wformat=2 -Wmissing-prototypes") endif() endif() diff --git a/Makefile b/Makefile @@ -20,14 +20,14 @@ INSTALL_LIBRARY_PATH = $(DESTDIR)$(PREFIX)/$(LIBRARY_PATH) INSTALL ?= cp -a -R_CFLAGS = -fPIC -std=c89 -pedantic -Wall -Werror -Wstrict-prototypes -Wwrite-strings $(CFLAGS) +R_CFLAGS = -fPIC -std=c89 -pedantic -Wall -Werror -Wstrict-prototypes -Wwrite-strings -Wshadow -Winit-self -Wcast-align -Wformat=2 -Wmissing-prototypes $(CFLAGS) uname := $(shell sh -c 'uname -s 2>/dev/null || echo false') #library file extensions SHARED = so STATIC = a - + ## create dynamic (shared) library on Darwin (base OS for MacOSX and IOS) ifeq (Darwin, $(uname)) SHARED = dylib diff --git a/test.c b/test.c @@ -25,7 +25,7 @@ #include "cJSON.h" /* Parse text to JSON, then render back to text, and print! */ -void doit(char *text) +static void doit(char *text) { char *out = NULL; cJSON *json = NULL; @@ -44,8 +44,9 @@ void doit(char *text) } } +#if 0 /* Read a file, parse, render back, etc. */ -void dofile(char *filename) +static void dofile(char *filename) { FILE *f = NULL; long len = 0; @@ -67,6 +68,7 @@ void dofile(char *filename) doit(data); free(data); } +#endif /* Used by some code below as an example datatype. */ struct record @@ -82,7 +84,7 @@ struct record }; /* Create a bunch of objects as demonstration. */ -void create_objects(void) +static void create_objects(void) { /* declare a few. */ cJSON *root = NULL; diff --git a/test_utils.c b/test_utils.c @@ -96,14 +96,14 @@ int main(void) printf("JSON Apply Patch Tests\n"); for (i = 0; i < 15; i++) { - cJSON *object = cJSON_Parse(patches[i][0]); + cJSON *object_to_be_patched = cJSON_Parse(patches[i][0]); cJSON *patch = cJSON_Parse(patches[i][1]); - int err = cJSONUtils_ApplyPatches(object, patch); - char *output = cJSON_Print(object); + int err = cJSONUtils_ApplyPatches(object_to_be_patched, patch); + char *output = cJSON_Print(object_to_be_patched); printf("Test %d (err %d):\n%s\n\n", i + 1, err, output); free(output); - cJSON_Delete(object); + cJSON_Delete(object_to_be_patched); cJSON_Delete(patch); } @@ -168,19 +168,19 @@ int main(void) printf("JSON Merge Patch tests\n"); for (i = 0; i < 15; i++) { - cJSON *object = cJSON_Parse(merges[i][0]); + cJSON *object_to_be_merged = cJSON_Parse(merges[i][0]); cJSON *patch = cJSON_Parse(merges[i][1]); - char *before = cJSON_PrintUnformatted(object); + char *before_merge = cJSON_PrintUnformatted(object_to_be_merged); patchtext = cJSON_PrintUnformatted(patch); - printf("Before: [%s] -> [%s] = ", before, patchtext); - object = cJSONUtils_MergePatch(object, patch); - after = cJSON_PrintUnformatted(object); + printf("Before: [%s] -> [%s] = ", before_merge, patchtext); + object_to_be_merged = cJSONUtils_MergePatch(object_to_be_merged, patch); + after = cJSON_PrintUnformatted(object_to_be_merged); printf("[%s] vs [%s] (%s)\n", after, merges[i][2], strcmp(after, merges[i][2]) ? "FAIL" : "OK"); - free(before); + free(before_merge); free(patchtext); free(after); - cJSON_Delete(object); + cJSON_Delete(object_to_be_merged); cJSON_Delete(patch); }