]> granicus.if.org Git - json-c/commitdiff
Enable -Werror and fix a number of minor warnings that existed.
authorEric Haszlakiewicz <erh+git@nimenees.com>
Sat, 9 Feb 2013 22:35:24 +0000 (16:35 -0600)
committerEric Haszlakiewicz <erh+git@nimenees.com>
Sat, 9 Feb 2013 22:35:24 +0000 (16:35 -0600)
Makefile.am.inc
json_tokener.c
json_util.c
linkhash.c
tests/parse_flags.c
tests/test_parse.c
tests/test_printbuf.c

index 7882fd75e2c0636e98c3ef4db5a87964c3988d4d..96a791ae55ae4a63565d78301bb499724afb947c 100644 (file)
@@ -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
 
index 6c5924ba1d1d1b6f74d23a129ab01be902b61298..e0edca06ae7499db35cb437b23a273eef41e1bbb 100644 (file)
@@ -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;
index 4030cbef53b3efd8d99d7aeafb095ff394d540cf..4e4e00cee1fff969e683a62c86fbcc31b65c5a4d 100644 (file)
@@ -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;
index 2661823925aa402bd27a1833a9244bc9558ffea4..50431485e91de85bedab4ddf8d1e13f5504c6709 100644 (file)
@@ -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;
index e33ffee3b83436d161b0abf69663b41ab411f3c7..1af61ea418df7f21b4713e688e521cbe142348d4 100644 (file)
@@ -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)
                        {
index 3e86c5ad52b127b0cfa1f60c9cad66d69895f5de..481cb123d8b6c7c79f9d842239e53afc78bb2c3d 100644 (file)
@@ -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()
index fed185e1e779ba01d5575e71c78c209a848619a5..c8b8ad036be2fb8a60c8cc419a1adafba3f000b3 100644 (file)
@@ -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);