From: Eric Haszlakiewicz Date: Sat, 9 Feb 2013 22:35:24 +0000 (-0600) Subject: Enable -Werror and fix a number of minor warnings that existed. X-Git-Tag: json-c-0.11-20130402~17 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=ca8b27d1836ff97935d2eb212f762f63b9258cbd;p=thirdparty%2Fjson-c.git Enable -Werror and fix a number of minor warnings that existed. --- diff --git a/Makefile.am.inc b/Makefile.am.inc index 7882fd75..96a791ae 100644 --- a/Makefile.am.inc +++ b/Makefile.am.inc @@ -1,2 +1,2 @@ -AM_CFLAGS = -Wall -Wextra -Wwrite-strings -Wno-unused-parameter -std=c99 -D_GNU_SOURCE -D_REENTRANT +AM_CFLAGS = -Wall -Werror -Wextra -Wwrite-strings -Wno-unused-parameter -std=c99 -D_GNU_SOURCE -D_REENTRANT diff --git a/json_tokener.c b/json_tokener.c index 6c5924ba..e0edca06 100644 --- a/json_tokener.c +++ b/json_tokener.c @@ -69,7 +69,8 @@ const char* json_tokener_errors[] = { const char *json_tokener_error_desc(enum json_tokener_error jerr) { - if (jerr < 0 || jerr > sizeof(json_tokener_errors)) + int jerr_int = (int)jerr; + if (jerr_int < 0 || jerr_int > (int)sizeof(json_tokener_errors)) return "Unknown error, invalid json_tokener_error value passed to json_tokener_error_desc()"; return json_tokener_errors[jerr]; } @@ -91,7 +92,7 @@ struct json_tokener* json_tokener_new_ex(int depth) tok = (struct json_tokener*)calloc(1, sizeof(struct json_tokener)); if (!tok) return NULL; - tok->stack = (struct json_tokener*)calloc(depth, sizeof(struct json_tokener_srec)); + tok->stack = (struct json_tokener_srec *)calloc(depth, sizeof(struct json_tokener_srec)); if (!tok->stack) { free(tok); return NULL; @@ -330,8 +331,8 @@ struct json_object* json_tokener_parse_ex(struct json_tokener *tok, case json_tokener_state_null: printbuf_memappend_fast(tok->pb, &c, 1); if(strncasecmp(json_null_str, tok->pb->buf, - json_min(tok->st_pos+1, strlen(json_null_str))) == 0) { - if(tok->st_pos == strlen(json_null_str)) { + json_min(tok->st_pos+1, (int)strlen(json_null_str))) == 0) { + if(tok->st_pos == (int)strlen(json_null_str)) { current = NULL; saved_state = json_tokener_state_finish; state = json_tokener_state_eatws; @@ -552,16 +553,16 @@ struct json_object* json_tokener_parse_ex(struct json_tokener *tok, case json_tokener_state_boolean: printbuf_memappend_fast(tok->pb, &c, 1); if(strncasecmp(json_true_str, tok->pb->buf, - json_min(tok->st_pos+1, strlen(json_true_str))) == 0) { - if(tok->st_pos == strlen(json_true_str)) { + json_min(tok->st_pos+1, (int)strlen(json_true_str))) == 0) { + if(tok->st_pos == (int)strlen(json_true_str)) { current = json_object_new_boolean(1); saved_state = json_tokener_state_finish; state = json_tokener_state_eatws; goto redo_char; } } else if(strncasecmp(json_false_str, tok->pb->buf, - json_min(tok->st_pos+1, strlen(json_false_str))) == 0) { - if(tok->st_pos == strlen(json_false_str)) { + json_min(tok->st_pos+1, (int)strlen(json_false_str))) == 0) { + if(tok->st_pos == (int)strlen(json_false_str)) { current = json_object_new_boolean(0); saved_state = json_tokener_state_finish; state = json_tokener_state_eatws; diff --git a/json_util.c b/json_util.c index 4030cbef..4e4e00ce 100644 --- a/json_util.c +++ b/json_util.c @@ -194,7 +194,7 @@ int json_parse_int64(const char *buf, int64_t *retval) */ if (orig_has_neg != recheck_has_neg || strncmp(buf_skip_space, buf_cmp_start, strlen(buf_cmp_start)) != 0 || - (strlen(buf_skip_space) != buf_cmp_len && + ((int)strlen(buf_skip_space) != buf_cmp_len && isdigit((int)buf_skip_space[buf_cmp_len]) ) ) @@ -238,7 +238,8 @@ static const char* json_type_name[] = { const char *json_type_to_name(enum json_type o_type) { - if (o_type < 0 || o_type >= NELEM(json_type_name)) + int o_type_int = (int)o_type; + if (o_type_int < 0 || o_type_int >= (int)NELEM(json_type_name)) { MC_ERROR("json_type_to_name: type %d is out of range [0,%d]\n", o_type, NELEM(json_type_name)); return NULL; diff --git a/linkhash.c b/linkhash.c index 26618239..50431485 100644 --- a/linkhash.c +++ b/linkhash.c @@ -134,7 +134,7 @@ int lh_table_insert(struct lh_table *t, void *k, const void *v) while( 1 ) { if(t->table[n].k == LH_EMPTY || t->table[n].k == LH_FREED) break; t->collisions++; - if(++n == t->size) n = 0; + if ((int)++n == t->size) n = 0; } t->table[n].k = k; @@ -166,7 +166,7 @@ struct lh_entry* lh_table_lookup_entry(struct lh_table *t, const void *k) if(t->table[n].k == LH_EMPTY) return NULL; if(t->table[n].k != LH_FREED && t->equal_fn(t->table[n].k, k)) return &t->table[n]; - if(++n == t->size) n = 0; + if ((int)++n == t->size) n = 0; count++; } return NULL; diff --git a/tests/parse_flags.c b/tests/parse_flags.c index e33ffee3..1af61ea4 100644 --- a/tests/parse_flags.c +++ b/tests/parse_flags.c @@ -32,7 +32,7 @@ int parse_flags(int argc, char **argv) for (arg_idx = 1; arg_idx < argc ; arg_idx++) { int jj; - for (jj = 0; jj < NELEM(format_args); jj++) + for (jj = 0; jj < (int)NELEM(format_args); jj++) { if (strcasecmp(argv[arg_idx], format_args[jj].arg) == 0) { diff --git a/tests/test_parse.c b/tests/test_parse.c index 3e86c5ad..481cb123 100644 --- a/tests/test_parse.c +++ b/tests/test_parse.c @@ -183,7 +183,7 @@ struct incremental_step { { "[1,2,3,]", -1, -1, json_tokener_success, 0 }, { "[1,2,,3,]", -1, 5, json_tokener_error_parse_unexpected, 0 }, - { NULL, json_tokener_success }, + { NULL, -1, -1, json_tokener_success, 0 }, }; static void test_incremental_parse() diff --git a/tests/test_printbuf.c b/tests/test_printbuf.c index fed185e1..c8b8ad03 100644 --- a/tests/test_printbuf.c +++ b/tests/test_printbuf.c @@ -86,7 +86,7 @@ static void test_printbuf_memappend(int *before_resize) char with_nulls[] = { 'a', 'b', '\0', 'c' }; printbuf_reset(pb); - printbuf_memappend_fast(pb, with_nulls, sizeof(with_nulls)); + printbuf_memappend_fast(pb, with_nulls, (int)sizeof(with_nulls)); printf("With embedded \\0 character: %d, [%s]\n", printbuf_length(pb), pb->buf); printbuf_free(pb);