From 16e22d634a42cbf3527d56174efe94b65099adaf Mon Sep 17 00:00:00 2001 From: Pawel Winogrodzki Date: Wed, 29 Mar 2017 13:03:38 -0700 Subject: [PATCH 1/3] Fixing all W4-level warnings. --- cJSON.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/cJSON.c b/cJSON.c index 98b997ce..55f6be8a 100644 --- a/cJSON.c +++ b/cJSON.c @@ -23,7 +23,10 @@ /* cJSON */ /* JSON parser in C. */ +#ifdef __GNUC__ #pragma GCC visibility push(default) +#endif + #include #include #include @@ -31,7 +34,10 @@ #include #include #include + +#ifdef __GNUC__ #pragma GCC visibility pop +#endif #include "cJSON.h" @@ -935,7 +941,7 @@ static parse_buffer *buffer_skip_whitespace(parse_buffer * const 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) { - parse_buffer buffer; + parse_buffer buffer = { 0 }; cJSON *item = NULL; /* reset error position */ @@ -1019,7 +1025,9 @@ CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value) return cJSON_ParseWithOpts(value, 0, 0); } +#ifndef min #define min(a, b) ((a < b) ? a : b) +#endif static unsigned char *print(const cJSON * const item, cJSON_bool format, const internal_hooks * const hooks) { @@ -1666,7 +1674,7 @@ CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON *object, const char *strin return c; } -CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string) +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * object, const char * string) { cJSON *current_element = NULL; @@ -1750,7 +1758,10 @@ CJSON_PUBLIC(void) cJSON_AddItemToObject(cJSON *object, const char *string, cJSO #if defined (__clang__) || ((__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) #pragma GCC diagnostic push #endif +#ifdef __GNUC__ #pragma GCC diagnostic ignored "-Wcast-qual" +#endif + /* Add an item to an object with constant string as key */ CJSON_PUBLIC(void) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item) { From 2ea410c5538a16edda446613b62ae6b9f76c2ef8 Mon Sep 17 00:00:00 2001 From: Pawel Winogrodzki Date: Thu, 30 Mar 2017 15:41:27 -0700 Subject: [PATCH 2/3] Adding back "const". --- cJSON.c | 2 +- cJSON.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cJSON.c b/cJSON.c index 55f6be8a..4541569a 100644 --- a/cJSON.c +++ b/cJSON.c @@ -1674,7 +1674,7 @@ CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON *object, const char *strin return c; } -CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * object, const char * string) +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string) { cJSON *current_element = NULL; diff --git a/cJSON.h b/cJSON.h index 80f0885a..56e6c603 100644 --- a/cJSON.h +++ b/cJSON.h @@ -144,7 +144,7 @@ CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array); CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int item); /* Get item "string" from object. Case insensitive. */ CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON *object, const char *string); -CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON *object, const char *string); +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string); CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string); /* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */ CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void); From 31f0fff5fa397a620d05693a4fe0825d8c359c4e Mon Sep 17 00:00:00 2001 From: Pawel Winogrodzki Date: Thu, 30 Mar 2017 15:47:06 -0700 Subject: [PATCH 3/3] Renaming "min" to "cjson_min". --- cJSON.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cJSON.c b/cJSON.c index 4541569a..74796c2f 100644 --- a/cJSON.c +++ b/cJSON.c @@ -1025,9 +1025,7 @@ CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value) return cJSON_ParseWithOpts(value, 0, 0); } -#ifndef min -#define min(a, b) ((a < b) ? a : b) -#endif +#define cjson_min(a, b) ((a < b) ? a : b) static unsigned char *print(const cJSON * const item, cJSON_bool format, const internal_hooks * const hooks) { @@ -1066,7 +1064,7 @@ static unsigned char *print(const cJSON * const item, cJSON_bool format, const i { goto fail; } - memcpy(printed, buffer->buffer, min(buffer->length, buffer->offset + 1)); + memcpy(printed, buffer->buffer, cjson_min(buffer->length, buffer->offset + 1)); printed[buffer->offset] = '\0'; /* just to be sure */ /* free the buffer */