From 2387d9d423ffe05b4fb54f9a0bafde0df971179a Mon Sep 17 00:00:00 2001 From: Kyle Chisholm Date: Fri, 25 Nov 2016 04:53:22 -0500 Subject: [PATCH 01/12] added Print function call for pre-allocated buffer --- cJSON.c | 10 ++++++++++ cJSON.h | 6 ++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/cJSON.c b/cJSON.c index 766e558e..19a04038 100644 --- a/cJSON.c +++ b/cJSON.c @@ -886,6 +886,16 @@ char *cJSON_PrintBuffered(const cJSON *item, int prebuffer, cjbool fmt) return print_value(item, 0, fmt, &p); } +int cJSON_PrintMallocedBuffer(cJSON *item,char *buf,const size_t len, cjbool fmt) +{ + char *out; + printbuffer p; + p.buffer = buf; + p.length = len; + p.offset = 0; + out = print_value(item,0,fmt,&p); + return (out != buf ? -1 : 0); +} /* Parser core - when encountering text, process appropriately. */ static const char *parse_value(cJSON *item, const char *value, const char **ep) diff --git a/cJSON.h b/cJSON.h index dbbb739f..f7063b7f 100644 --- a/cJSON.h +++ b/cJSON.h @@ -83,8 +83,10 @@ extern char *cJSON_Print(const cJSON *item); extern char *cJSON_PrintUnformatted(const cJSON *item); /* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */ extern char *cJSON_PrintBuffered(const cJSON *item, int prebuffer, int fmt); -/* Delete a cJSON entity and all subentities. */ -extern void cJSON_Delete(cJSON *c); +/* Render a cJSON entity to text using a buffer already allocated in memory with length buf_len */ +extern int cJSON_PrintMallocedBuffer(cJSON *item,char *buf,const size_t len, int fmt); +/* Delete a cJSON entity and all subentities. */ +extern void cJSON_Delete(cJSON *c); /* Returns the number of items in an array (or object). */ extern int cJSON_GetArraySize(const cJSON *array); From 1193d240caf6b59e4747dce8f065c9c5b6ecf430 Mon Sep 17 00:00:00 2001 From: Kyle Chisholm Date: Fri, 25 Nov 2016 04:55:38 -0500 Subject: [PATCH 02/12] fixed "make test" on Mac (clang) --- Makefile | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index b633c806..614b7c1b 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,9 @@ UTILS_LIBNAME = libcjson_utils CJSON_TEST = cJSON_test UTILS_TEST = cJSON_test_utils +CJSON_TEST_SRC = cJSON.c test.c +UTILS_TEST_SRC = cJSON.c cJSON_Utils.c test_utils.c + LDLIBS = -lm LIBVERSION = 1.0.2 @@ -66,11 +69,11 @@ test: tests #tests #cJSON -$(CJSON_TEST): cJSON.c cJSON.h test.c - $(CC) $^ -o $@ $(LDLIBS) -I. +$(CJSON_TEST): $(CJSON_TEST_SRC) cJSON.h + $(CC) $(CJSON_TEST_SRC) -o $@ $(LDLIBS) -I. #cJSON_Utils -$(UTILS_TEST): cJSON.c cJSON.h test.c - $(CC) $^ -o $@ $(LDLIBS) -I. +$(UTILS_TEST): $(UTILS_TEST_SRC) cJSON.h cJSON_Utils.h + $(CC) $(UTILS_TEST_SRC) -o $@ $(LDLIBS) -I. #static libraries #cJSON From df093c380efdfcffedec39f8b75e0262c090d8c9 Mon Sep 17 00:00:00 2001 From: Kyle Chisholm Date: Fri, 25 Nov 2016 05:28:21 -0500 Subject: [PATCH 03/12] fix shared utils library to also include cjson object --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 614b7c1b..94edeb12 100644 --- a/Makefile +++ b/Makefile @@ -88,8 +88,8 @@ $(UTILS_STATIC): $(UTILS_OBJ) $(CJSON_SHARED_VERSION): $(CJSON_OBJ) $(CC) -shared -o $@ $< $(LDFLAGS) #cJSON_Utils -$(UTILS_SHARED_VERSION): $(UTILS_OBJ) - $(CC) -shared -o $@ $< $(LDFLAGS) +$(UTILS_SHARED_VERSION): $(UTILS_OBJ) $(CJSON_OBJ) + $(CC) -shared -o $@ $< $(CJSON_OBJ) $(LDFLAGS) #objects #cJSON From 42496b2d9d18e76b968a6a040b7d31a0817f98d9 Mon Sep 17 00:00:00 2001 From: Kyle Chisholm Date: Fri, 25 Nov 2016 13:33:10 -0500 Subject: [PATCH 04/12] changed to cJSON_PrintPreallocated, added flag in printbuffer --- cJSON.c | 17 +++++++++++++++-- cJSON.h | 6 +++--- test.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 65 insertions(+), 7 deletions(-) diff --git a/cJSON.c b/cJSON.c index 19a04038..daf46928 100644 --- a/cJSON.c +++ b/cJSON.c @@ -244,8 +244,10 @@ typedef struct char *buffer; int length; int offset; + int noalloc; } printbuffer; + /* realloc printbuffer if necessary to have at least "needed" bytes more */ static char* ensure(printbuffer *p, int needed) { @@ -261,12 +263,17 @@ static char* ensure(printbuffer *p, int needed) return p->buffer + p->offset; } + if (p->noalloc) { + return NULL; + } + newsize = pow2gt(needed); newbuffer = (char*)cJSON_malloc(newsize); if (!newbuffer) { cJSON_free(p->buffer); p->length = 0; + p->noalloc = 0; p->buffer = NULL; return NULL; @@ -882,17 +889,19 @@ char *cJSON_PrintBuffered(const cJSON *item, int prebuffer, cjbool fmt) } p.length = prebuffer; p.offset = 0; + p.noalloc = 0; return print_value(item, 0, fmt, &p); } -int cJSON_PrintMallocedBuffer(cJSON *item,char *buf,const size_t len, cjbool fmt) +int cJSON_PrintPreallocated(cJSON *item,char *buf, const size_t len, const cjbool fmt) { char *out; printbuffer p; p.buffer = buf; p.length = len; p.offset = 0; + p.noalloc = 1; out = print_value(item,0,fmt,&p); return (out != buf ? -1 : 0); } @@ -1147,7 +1156,11 @@ static char *print_array(const cJSON *item, int depth, cjbool fmt, printbuffer * child = item->child; while (child && !fail) { - print_value(child, depth + 1, fmt, p); + ptr = print_value(child, depth + 1, fmt, p); + if (!ptr) + { + return NULL; + } p->offset = update(p); if (child->next) { diff --git a/cJSON.h b/cJSON.h index f7063b7f..af5082ac 100644 --- a/cJSON.h +++ b/cJSON.h @@ -84,9 +84,9 @@ extern char *cJSON_PrintUnformatted(const cJSON *item); /* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */ extern char *cJSON_PrintBuffered(const cJSON *item, int prebuffer, int fmt); /* Render a cJSON entity to text using a buffer already allocated in memory with length buf_len */ -extern int cJSON_PrintMallocedBuffer(cJSON *item,char *buf,const size_t len, int fmt); -/* Delete a cJSON entity and all subentities. */ -extern void cJSON_Delete(cJSON *c); +extern int cJSON_PrintPreallocated(cJSON *item, char *buf, const size_t len, const int fmt); +/* Delete a cJSON entity and all subentities. */ +extern void cJSON_Delete(cJSON *c); /* Returns the number of items in an array (or object). */ extern int cJSON_GetArraySize(const cJSON *array); diff --git a/test.c b/test.c index 7706d97b..19528586 100644 --- a/test.c +++ b/test.c @@ -22,6 +22,7 @@ #include #include +#include #include "cJSON.h" /* Parse text to JSON, then render back to text, and print! */ @@ -219,16 +220,60 @@ void create_objects(void) /* cJSON_ReplaceItemInObject(cJSON_GetArrayItem(root, 1), "City", cJSON_CreateIntArray(ids, 4)); */ out = cJSON_Print(root); - cJSON_Delete(root); printf("%s\n", out); + + printf("Test cJSON_PrintPreallocated:\n"); + /* create buffer */ + size_t len = strlen(out) + 1; + char *buf = malloc(len); + + /* create buffer to fail */ + size_t len_fail = strlen(out); + char *buf_fail = malloc(len_fail); + free(out); + /* Print to buffer */ + if (cJSON_PrintPreallocated(root, buf, len, 1) != 0) { + printf("cJSON_PrintPreallocated failed (but it should not have!)\n"); + free(buf_fail); + free(buf); + exit(EXIT_FAILURE); + } else { + printf("cJSON_PrintPreallocated:\n%s\n", buf); + } + + /* unformatted output */ + if (cJSON_PrintPreallocated(root, buf, len, 0) != 0) { + printf("cJSON_PrintPreallocated failed (but it should not have!)\n"); + free(buf_fail); + free(buf); + exit(EXIT_FAILURE); + } else { + printf("cJSON_PrintPreallocated (unformatted):\n%s\n", buf); + } + + free(buf); + + /* force it to fail */ + if (cJSON_PrintPreallocated(root, buf_fail, len_fail, 1) != 0) { + printf("cJSON_PrintPreallocated failed (as expected)\n"); + } else { + printf("cJSON_PrintPreallocated worked (but it should have failed!)\n"); + printf("cJSON_PrintPreallocated:\n%s\n", buf_fail); + } + + free(buf_fail); + cJSON_Delete(root); + root = cJSON_CreateObject(); cJSON_AddNumberToObject(root, "number", 1.0 / zero); out = cJSON_Print(root); - cJSON_Delete(root); printf("%s\n", out); + cJSON_Delete(root); + free(out); + } int main(void) From 4150c30a1747290815736d8a09bb7364ee31e334 Mon Sep 17 00:00:00 2001 From: Kyle Chisholm Date: Mon, 28 Nov 2016 03:19:50 -0500 Subject: [PATCH 05/12] change noalloc struct item to cjbool --- cJSON.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cJSON.c b/cJSON.c index daf46928..bb16521a 100644 --- a/cJSON.c +++ b/cJSON.c @@ -244,10 +244,9 @@ typedef struct char *buffer; int length; int offset; - int noalloc; + cjbool noalloc; } printbuffer; - /* realloc printbuffer if necessary to have at least "needed" bytes more */ static char* ensure(printbuffer *p, int needed) { @@ -273,7 +272,7 @@ static char* ensure(printbuffer *p, int needed) { cJSON_free(p->buffer); p->length = 0; - p->noalloc = 0; + p->noalloc = false; p->buffer = NULL; return NULL; @@ -889,7 +888,7 @@ char *cJSON_PrintBuffered(const cJSON *item, int prebuffer, cjbool fmt) } p.length = prebuffer; p.offset = 0; - p.noalloc = 0; + p.noalloc = false; return print_value(item, 0, fmt, &p); } @@ -901,7 +900,7 @@ int cJSON_PrintPreallocated(cJSON *item,char *buf, const size_t len, const cjboo p.buffer = buf; p.length = len; p.offset = 0; - p.noalloc = 1; + p.noalloc = true; out = print_value(item,0,fmt,&p); return (out != buf ? -1 : 0); } From 6ce0915f530fea2b650da80e871461e00d2f2927 Mon Sep 17 00:00:00 2001 From: Kyle Chisholm Date: Mon, 28 Nov 2016 03:20:34 -0500 Subject: [PATCH 06/12] check print_value return --- cJSON.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cJSON.c b/cJSON.c index bb16521a..b9ae40ba 100644 --- a/cJSON.c +++ b/cJSON.c @@ -1155,8 +1155,7 @@ static char *print_array(const cJSON *item, int depth, cjbool fmt, printbuffer * child = item->child; while (child && !fail) { - ptr = print_value(child, depth + 1, fmt, p); - if (!ptr) + if (!print_value(child, depth + 1, fmt, p)) { return NULL; } @@ -1473,7 +1472,10 @@ static char *print_object(const cJSON *item, int depth, cjbool fmt, printbuffer p->offset+=len; /* print value */ - print_value(child, depth, fmt, p); + if (!print_value(child, depth, fmt, p)) + { + return NULL; + }; p->offset = update(p); /* print comma if not last */ From 6e1b4ba71bb439b5d1d90f232b194b0743da92d4 Mon Sep 17 00:00:00 2001 From: Kyle Chisholm Date: Mon, 28 Nov 2016 03:21:15 -0500 Subject: [PATCH 07/12] function to print and compare to preallocated buffer --- test.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/test.c b/test.c index 19528586..7e17dff4 100644 --- a/test.c +++ b/test.c @@ -82,6 +82,63 @@ struct record const char *country; }; + +/* Create a bunch of objects as demonstration. */ +int print_preallocated(cJSON *root) +{ + /* declarations */ + char *out = NULL; + char *buf = NULL; + char *buf_fail = NULL; + int len = 0; + int len_fail = 0; + + /* formatted print */ + out = cJSON_Print(root); + + /* create buffer to succeed */ + /* the extra 64 bytes are in case a floating point value is printed */ + len = strlen(out) + 64; + buf = malloc(len); + + /* create buffer to fail */ + len_fail = strlen(out); + buf_fail = malloc(len_fail); + + /* Print to buffer */ + if (cJSON_PrintPreallocated(root, buf, len, 1) != 0) { + printf("cJSON_PrintPreallocated failed!\n"); + if (strcmp(out, buf) != 0) { + printf("cJSON_PrintPreallocated not the same as cJSON_Print!\n"); + printf("cJSON_Print result:\n%s\n", out); + printf("cJSON_PrintPreallocated result:\n%s\n", buf); + } + free(out); + free(buf_fail); + free(buf); + return -1; + } + + /* success */ + printf("%s\n", buf); + + /* force it to fail */ + if (cJSON_PrintPreallocated(root, buf_fail, len_fail, 1) == 0) { + printf("cJSON_PrintPreallocated failed to show error with insufficient memory!\n"); + printf("cJSON_Print result:\n%s\n", out); + printf("cJSON_PrintPreallocated result:\n%s\n", buf_fail); + free(out); + free(buf_fail); + free(buf); + return -1; + } + + free(out); + free(buf_fail); + free(buf); + return 0; +} + /* Create a bunch of objects as demonstration. */ void create_objects(void) { From 652bb777e3a18369d34a31e1e924e1ede76e0539 Mon Sep 17 00:00:00 2001 From: Kyle Chisholm Date: Mon, 28 Nov 2016 03:24:02 -0500 Subject: [PATCH 08/12] use print_preallocated function to test printout of JSON --- test.c | 89 +++++++++++++++------------------------------------------- 1 file changed, 23 insertions(+), 66 deletions(-) diff --git a/test.c b/test.c index 7e17dff4..7a45c345 100644 --- a/test.c +++ b/test.c @@ -148,7 +148,6 @@ void create_objects(void) cJSON *img = NULL; cJSON *thm = NULL; cJSON *fld = NULL; - char *out = NULL; int i = 0; /* Our "days of the week" array: */ @@ -210,21 +209,20 @@ void create_objects(void) cJSON_AddNumberToObject(fmt, "frame rate", 24); /* Print to text */ - out = cJSON_Print(root); - /* Delete the cJSON */ + if (print_preallocated(root) != 0) { + cJSON_Delete(root); + exit(EXIT_FAILURE); + } cJSON_Delete(root); - /* print it */ - printf("%s\n",out); - /* release the string */ - free(out); /* Our "days of the week" array: */ root = cJSON_CreateStringArray(strings, 7); - out = cJSON_Print(root); + if (print_preallocated(root) != 0) { + cJSON_Delete(root); + exit(EXIT_FAILURE); + } cJSON_Delete(root); - printf("%s\n", out); - free(out); /* Our matrix: */ root = cJSON_CreateArray(); @@ -235,11 +233,11 @@ void create_objects(void) /* cJSON_ReplaceItemInArray(root, 1, cJSON_CreateString("Replacement")); */ - out = cJSON_Print(root); + if (print_preallocated(root) != 0) { + cJSON_Delete(root); + exit(EXIT_FAILURE); + } cJSON_Delete(root); - printf("%s\n", out); - free(out); - /* Our "gallery" item: */ root = cJSON_CreateObject(); @@ -253,13 +251,13 @@ void create_objects(void) cJSON_AddStringToObject(thm, "Width", "100"); cJSON_AddItemToObject(img, "IDs", cJSON_CreateIntArray(ids, 4)); - out = cJSON_Print(root); + if (print_preallocated(root) != 0) { + cJSON_Delete(root); + exit(EXIT_FAILURE); + } cJSON_Delete(root); - printf("%s\n", out); - free(out); /* Our array of "records": */ - root = cJSON_CreateArray(); for (i = 0; i < 2; i++) { @@ -276,61 +274,20 @@ void create_objects(void) /* cJSON_ReplaceItemInObject(cJSON_GetArrayItem(root, 1), "City", cJSON_CreateIntArray(ids, 4)); */ - out = cJSON_Print(root); - printf("%s\n", out); - - printf("Test cJSON_PrintPreallocated:\n"); - /* create buffer */ - size_t len = strlen(out) + 1; - char *buf = malloc(len); - - /* create buffer to fail */ - size_t len_fail = strlen(out); - char *buf_fail = malloc(len_fail); - - free(out); - - /* Print to buffer */ - if (cJSON_PrintPreallocated(root, buf, len, 1) != 0) { - printf("cJSON_PrintPreallocated failed (but it should not have!)\n"); - free(buf_fail); - free(buf); - exit(EXIT_FAILURE); - } else { - printf("cJSON_PrintPreallocated:\n%s\n", buf); - } - - /* unformatted output */ - if (cJSON_PrintPreallocated(root, buf, len, 0) != 0) { - printf("cJSON_PrintPreallocated failed (but it should not have!)\n"); - free(buf_fail); - free(buf); + if (print_preallocated(root) != 0) { + cJSON_Delete(root); exit(EXIT_FAILURE); - } else { - printf("cJSON_PrintPreallocated (unformatted):\n%s\n", buf); - } - - free(buf); - - /* force it to fail */ - if (cJSON_PrintPreallocated(root, buf_fail, len_fail, 1) != 0) { - printf("cJSON_PrintPreallocated failed (as expected)\n"); - } else { - printf("cJSON_PrintPreallocated worked (but it should have failed!)\n"); - printf("cJSON_PrintPreallocated:\n%s\n", buf_fail); } - - free(buf_fail); cJSON_Delete(root); root = cJSON_CreateObject(); cJSON_AddNumberToObject(root, "number", 1.0 / zero); - out = cJSON_Print(root); - printf("%s\n", out); - cJSON_Delete(root); - - free(out); + if (print_preallocated(root) != 0) { + cJSON_Delete(root); + exit(EXIT_FAILURE); + } + cJSON_Delete(root); } int main(void) From e559516277762c7708cd90b17f5a02f7756b4e62 Mon Sep 17 00:00:00 2001 From: Kyle Chisholm Date: Mon, 28 Nov 2016 03:31:38 -0500 Subject: [PATCH 09/12] change buffer length to to int --- cJSON.c | 2 +- cJSON.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cJSON.c b/cJSON.c index b9ae40ba..89a530c3 100644 --- a/cJSON.c +++ b/cJSON.c @@ -893,7 +893,7 @@ char *cJSON_PrintBuffered(const cJSON *item, int prebuffer, cjbool fmt) return print_value(item, 0, fmt, &p); } -int cJSON_PrintPreallocated(cJSON *item,char *buf, const size_t len, const cjbool fmt) +int cJSON_PrintPreallocated(cJSON *item,char *buf, const int len, const cjbool fmt) { char *out; printbuffer p; diff --git a/cJSON.h b/cJSON.h index af5082ac..4d015c33 100644 --- a/cJSON.h +++ b/cJSON.h @@ -84,7 +84,7 @@ extern char *cJSON_PrintUnformatted(const cJSON *item); /* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */ extern char *cJSON_PrintBuffered(const cJSON *item, int prebuffer, int fmt); /* Render a cJSON entity to text using a buffer already allocated in memory with length buf_len */ -extern int cJSON_PrintPreallocated(cJSON *item, char *buf, const size_t len, const int fmt); +extern int cJSON_PrintPreallocated(cJSON *item, char *buf, const int len, const int fmt); /* Delete a cJSON entity and all subentities. */ extern void cJSON_Delete(cJSON *c); From e3e77260fd439c828e18aa4abae75dd4a6a2cf42 Mon Sep 17 00:00:00 2001 From: Kyle Chisholm Date: Mon, 28 Nov 2016 03:34:53 -0500 Subject: [PATCH 10/12] more concise return --- cJSON.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cJSON.c b/cJSON.c index 89a530c3..934a5967 100644 --- a/cJSON.c +++ b/cJSON.c @@ -895,14 +895,12 @@ char *cJSON_PrintBuffered(const cJSON *item, int prebuffer, cjbool fmt) int cJSON_PrintPreallocated(cJSON *item,char *buf, const int len, const cjbool fmt) { - char *out; printbuffer p; p.buffer = buf; p.length = len; p.offset = 0; p.noalloc = true; - out = print_value(item,0,fmt,&p); - return (out != buf ? -1 : 0); + return print_value(item,0,fmt,&p) != NULL; } /* Parser core - when encountering text, process appropriately. */ From 32f331609f389a78478225ba432f543d3bea7021 Mon Sep 17 00:00:00 2001 From: Kyle Chisholm Date: Mon, 28 Nov 2016 03:43:35 -0500 Subject: [PATCH 11/12] forgot to add 0, -1 return values --- cJSON.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cJSON.c b/cJSON.c index 934a5967..9d0b8611 100644 --- a/cJSON.c +++ b/cJSON.c @@ -900,7 +900,7 @@ int cJSON_PrintPreallocated(cJSON *item,char *buf, const int len, const cjbool f p.length = len; p.offset = 0; p.noalloc = true; - return print_value(item,0,fmt,&p) != NULL; + return (print_value(item,0,fmt,&p) != NULL ? 0 : -1); } /* Parser core - when encountering text, process appropriately. */ From 7083240101ce352c205aaed83976c358a925d36c Mon Sep 17 00:00:00 2001 From: Kyle Chisholm Date: Mon, 28 Nov 2016 03:56:01 -0500 Subject: [PATCH 12/12] fix flags --- Makefile | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 94edeb12..768cfd53 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ 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') @@ -48,8 +48,6 @@ UTILS_SHARED_VERSION = $(UTILS_LIBNAME).$(SHARED).$(LIBVERSION) UTILS_SHARED_SO = $(UTILS_LIBNAME).$(SHARED).$(UTILS_SOVERSION) UTILS_STATIC = $(UTILS_LIBNAME).$(STATIC) -SHARED_CMD = $(CC) -shared -o - .PHONY: all shared static tests clean install all: shared static tests @@ -65,15 +63,15 @@ test: tests ./$(UTILS_TEST) .c.o: - $(CC) -ansi -pedantic -c $(R_CFLAGS) $< + $(CC) -c $(R_CFLAGS) $< #tests #cJSON $(CJSON_TEST): $(CJSON_TEST_SRC) cJSON.h - $(CC) $(CJSON_TEST_SRC) -o $@ $(LDLIBS) -I. + $(CC) $(R_CFLAGS) $(CJSON_TEST_SRC) -o $@ $(LDLIBS) -I. #cJSON_Utils $(UTILS_TEST): $(UTILS_TEST_SRC) cJSON.h cJSON_Utils.h - $(CC) $(UTILS_TEST_SRC) -o $@ $(LDLIBS) -I. + $(CC) $(R_CFLAGS) $(UTILS_TEST_SRC) -o $@ $(LDLIBS) -I. #static libraries #cJSON @@ -86,10 +84,10 @@ $(UTILS_STATIC): $(UTILS_OBJ) #shared libraries .so.1.0.0 #cJSON $(CJSON_SHARED_VERSION): $(CJSON_OBJ) - $(CC) -shared -o $@ $< $(LDFLAGS) + $(CC) $(R_CFLAGS) -shared -o $@ $< $(LDFLAGS) #cJSON_Utils $(UTILS_SHARED_VERSION): $(UTILS_OBJ) $(CJSON_OBJ) - $(CC) -shared -o $@ $< $(CJSON_OBJ) $(LDFLAGS) + $(CC) $(R_CFLAGS) -shared -o $@ $< $(CJSON_OBJ) $(LDFLAGS) #objects #cJSON