Merge pull request #75 from gatzka/feature/enhance_gcc_checks_v2

Enhance gcc checks v2
This commit is contained in:
Max Bruckner 2016-11-28 00:58:45 +07:00 committed by GitHub
commit 1f0ad823c9
4 changed files with 19 additions and 17 deletions

View File

@ -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) option(ENABLE_CUSTOM_COMPILER_FLAGS "Enables custom compiler flags for Clang and GCC" ON)
if (ENABLE_CUSTOM_COMPILER_FLAGS) if (ENABLE_CUSTOM_COMPILER_FLAGS)
if(("${CMAKE_C_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")) 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()
endif() endif()

View File

@ -20,7 +20,7 @@ INSTALL_LIBRARY_PATH = $(DESTDIR)$(PREFIX)/$(LIBRARY_PATH)
INSTALL ?= cp -a 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') uname := $(shell sh -c 'uname -s 2>/dev/null || echo false')

8
test.c
View File

@ -25,7 +25,7 @@
#include "cJSON.h" #include "cJSON.h"
/* Parse text to JSON, then render back to text, and print! */ /* Parse text to JSON, then render back to text, and print! */
void doit(char *text) static void doit(char *text)
{ {
char *out = NULL; char *out = NULL;
cJSON *json = NULL; cJSON *json = NULL;
@ -44,8 +44,9 @@ void doit(char *text)
} }
} }
#if 0
/* Read a file, parse, render back, etc. */ /* Read a file, parse, render back, etc. */
void dofile(char *filename) static void dofile(char *filename)
{ {
FILE *f = NULL; FILE *f = NULL;
long len = 0; long len = 0;
@ -67,6 +68,7 @@ void dofile(char *filename)
doit(data); doit(data);
free(data); free(data);
} }
#endif
/* Used by some code below as an example datatype. */ /* Used by some code below as an example datatype. */
struct record struct record
@ -82,7 +84,7 @@ struct record
}; };
/* Create a bunch of objects as demonstration. */ /* Create a bunch of objects as demonstration. */
void create_objects(void) static void create_objects(void)
{ {
/* declare a few. */ /* declare a few. */
cJSON *root = NULL; cJSON *root = NULL;

View File

@ -96,14 +96,14 @@ int main(void)
printf("JSON Apply Patch Tests\n"); printf("JSON Apply Patch Tests\n");
for (i = 0; i < 15; i++) 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]); cJSON *patch = cJSON_Parse(patches[i][1]);
int err = cJSONUtils_ApplyPatches(object, patch); int err = cJSONUtils_ApplyPatches(object_to_be_patched, patch);
char *output = cJSON_Print(object); char *output = cJSON_Print(object_to_be_patched);
printf("Test %d (err %d):\n%s\n\n", i + 1, err, output); printf("Test %d (err %d):\n%s\n\n", i + 1, err, output);
free(output); free(output);
cJSON_Delete(object); cJSON_Delete(object_to_be_patched);
cJSON_Delete(patch); cJSON_Delete(patch);
} }
@ -168,19 +168,19 @@ int main(void)
printf("JSON Merge Patch tests\n"); printf("JSON Merge Patch tests\n");
for (i = 0; i < 15; i++) 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]); 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); patchtext = cJSON_PrintUnformatted(patch);
printf("Before: [%s] -> [%s] = ", before, patchtext); printf("Before: [%s] -> [%s] = ", before_merge, patchtext);
object = cJSONUtils_MergePatch(object, patch); object_to_be_merged = cJSONUtils_MergePatch(object_to_be_merged, patch);
after = cJSON_PrintUnformatted(object); after = cJSON_PrintUnformatted(object_to_be_merged);
printf("[%s] vs [%s] (%s)\n", after, merges[i][2], strcmp(after, merges[i][2]) ? "FAIL" : "OK"); 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(patchtext);
free(after); free(after);
cJSON_Delete(object); cJSON_Delete(object_to_be_merged);
cJSON_Delete(patch); cJSON_Delete(patch);
} }