diff options
author | Emmanuele Bassi <ebassi@gnome.org> | 2022-10-11 11:47:03 +0100 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gnome.org> | 2022-10-11 11:47:03 +0100 |
commit | d370ce7ed63ae53c828586f30e6b3f740bc3cbe3 (patch) | |
tree | 124e00fd8b6a667a6caa56157c5a58526b3bd017 | |
parent | cc294f1ff54fea728df97e0cb6bafc34a075af8d (diff) | |
download | json-glib-d370ce7ed63ae53c828586f30e6b3f740bc3cbe3.tar.gz |
Fix sign comparison warnings
When running with `-Wsign-compare` we're raising a lot of
signed/unsigned comparison warnings.
-rw-r--r-- | json-glib/json-array.c | 4 | ||||
-rw-r--r-- | json-glib/json-gvariant.c | 4 | ||||
-rw-r--r-- | json-glib/json-parser.c | 10 | ||||
-rw-r--r-- | json-glib/json-path.c | 6 | ||||
-rw-r--r-- | json-glib/tests/generator.c | 13 | ||||
-rw-r--r-- | json-glib/tests/gvariant.c | 22 | ||||
-rw-r--r-- | json-glib/tests/invalid.c | 4 | ||||
-rw-r--r-- | json-glib/tests/object.c | 4 | ||||
-rw-r--r-- | json-glib/tests/parser.c | 21 | ||||
-rw-r--r-- | json-glib/tests/path.c | 4 |
10 files changed, 34 insertions, 58 deletions
diff --git a/json-glib/json-array.c b/json-glib/json-array.c index b242ce7..200cd92 100644 --- a/json-glib/json-array.c +++ b/json-glib/json-array.c @@ -731,12 +731,10 @@ json_array_foreach_element (JsonArray *array, JsonArrayForeach func, gpointer data) { - gint i; - g_return_if_fail (array != NULL); g_return_if_fail (func != NULL); - for (i = 0; i < array->elements->len; i++) + for (guint i = 0; i < array->elements->len; i++) { JsonNode *element_node; diff --git a/json-glib/json-gvariant.c b/json-glib/json-gvariant.c index 15f03f5..31c8e13 100644 --- a/json-glib/json-gvariant.c +++ b/json-glib/json-gvariant.c @@ -529,7 +529,7 @@ json_to_gvariant_tuple (JsonNode *json_node, { GVariant *variant = NULL; JsonArray *array; - gint i; + guint i; GList *children = NULL; gboolean roll_back = FALSE; const gchar *initial_signature; @@ -737,7 +737,7 @@ json_to_gvariant_array (JsonNode *json_node, if (json_array_get_length (array) > 0) { - gint i; + guint i; guint len; len = json_array_get_length (array); diff --git a/json-glib/json-parser.c b/json-glib/json-parser.c index c5e58f4..1162ac6 100644 --- a/json-glib/json-parser.c +++ b/json-glib/json-parser.c @@ -950,7 +950,6 @@ static JsonScanner * json_scanner_create (JsonParser *parser) { JsonScanner *scanner; - gint i; scanner = json_scanner_new (); scanner->msg_handler = json_scanner_msg_handler; @@ -960,7 +959,7 @@ json_scanner_create (JsonParser *parser) * we cannot move them into JsonScanner without moving a bunch of code * as well */ - for (i = 0; i < n_symbols; i++) + for (guint i = 0; i < n_symbols; i++) { json_scanner_scope_add_symbol (scanner, 0, symbol_names + symbols[i].name_offset, @@ -1011,7 +1010,6 @@ json_parser_load (JsonParser *parser, JsonScanner *scanner; gboolean done; gboolean retval = TRUE; - gint i; gchar *data = input_data; json_parser_clear (parser); @@ -1053,7 +1051,7 @@ json_parser_load (JsonParser *parser, else { guint expected_token; - gint cur_token; + guint cur_token; /* we try to show the expected token, if possible */ expected_token = json_parse_statement (parser, scanner); @@ -1071,7 +1069,7 @@ json_parser_load (JsonParser *parser, if (expected_token > JSON_TOKEN_INVALID && expected_token < JSON_TOKEN_LAST) { - for (i = 0; i < n_symbols; i++) + for (guint i = 0; i < n_symbols; i++) if (symbols[i].token == expected_token) symbol_name = symbol_names + symbols[i].name_offset; @@ -1084,7 +1082,7 @@ json_parser_load (JsonParser *parser, { symbol_name = "???"; - for (i = 0; i < n_symbols; i++) + for (guint i = 0; i < n_symbols; i++) if (symbols[i].token == cur_token) symbol_name = symbol_names + symbols[i].name_offset; } diff --git a/json-glib/json-path.c b/json-glib/json-path.c index 86fe97f..a41d9b8 100644 --- a/json-glib/json-path.c +++ b/json-glib/json-path.c @@ -199,7 +199,7 @@ struct _PathNode union { /* JSON_PATH_NODE_CHILD_ELEMENT */ - int element_index; + guint element_index; /* JSON_PATH_NODE_CHILD_MEMBER */ char *member_name; @@ -302,7 +302,7 @@ json_path_foreach_print (gpointer data, break; case JSON_PATH_NODE_CHILD_ELEMENT: - g_string_append_printf (buf, "<element '%d'", cur_node->data.element_index); + g_string_append_printf (buf, "<element '%u'", cur_node->data.element_index); break; case JSON_PATH_NODE_RECURSIVE_DESCENT: @@ -781,7 +781,7 @@ walk_path_node (GList *path, { JsonArray *array = json_node_get_array (root); GList *members, *l; - int i; + guint i; members = json_array_get_elements (array); for (l = members, i = 0; l != NULL; l = l->next, i += 1) diff --git a/json-glib/tests/generator.c b/json-glib/tests/generator.c index 833d8fc..f6ac0f1 100644 --- a/json-glib/tests/generator.c +++ b/json-glib/tests/generator.c @@ -297,7 +297,6 @@ test_decimal_separator (void) JsonNode *node = json_node_new (JSON_NODE_VALUE); JsonGenerator *generator = json_generator_new (); gchar *old_locale; - gint i; json_node_set_double (node, 3.14); @@ -305,7 +304,7 @@ test_decimal_separator (void) old_locale = setlocale (LC_NUMERIC, NULL); - for (i = 0; i < G_N_ELEMENTS (decimal_separator); i++) + for (guint i = 0; i < G_N_ELEMENTS (decimal_separator); i++) { gchar *str, *expected; @@ -434,10 +433,6 @@ int main (int argc, char *argv[]) { - gchar *escaped; - gchar *name; - gint i; - g_test_init (&argc, &argv, NULL); g_test_add_func ("/generator/empty-array", test_empty_array); @@ -450,10 +445,10 @@ main (int argc, g_test_add_func ("/generator/double-stays-double", test_double_stays_double); g_test_add_func ("/generator/pretty", test_pretty); - for (i = 0; i < G_N_ELEMENTS (string_fixtures); i++) + for (guint i = 0; i < G_N_ELEMENTS (string_fixtures); i++) { - escaped = g_strescape (string_fixtures[i].str, NULL); - name = g_strdup_printf ("/generator/string/%s", escaped); + char *escaped = g_strescape (string_fixtures[i].str, NULL); + char *name = g_strdup_printf ("/generator/string/%s", escaped); g_test_add_data_func (name, string_fixtures + i, test_string_encode); g_free (escaped); g_free (name); diff --git a/json-glib/tests/gvariant.c b/json-glib/tests/gvariant.c index 3f2bc13..805da00 100644 --- a/json-glib/tests/gvariant.c +++ b/json-glib/tests/gvariant.c @@ -216,17 +216,13 @@ test_json_to_gvariant (gconstpointer test_data) gint main (gint argc, gchar *argv[]) { - gint i; - TestCase test_case; - gchar *test_name; - g_test_init (&argc, &argv, NULL); /* GVariant to JSON */ - for (i = 0; i < G_N_ELEMENTS (two_way_test_cases); i++) + for (guint i = 0; i < G_N_ELEMENTS (two_way_test_cases); i++) { - test_case = two_way_test_cases[i]; - test_name = g_strdup_printf ("/gvariant/to-json/%s", test_case.test_name); + TestCase test_case = two_way_test_cases[i]; + char *test_name = g_strdup_printf ("/gvariant/to-json/%s", test_case.test_name); g_test_add_data_func (test_name, &two_way_test_cases[i], test_gvariant_to_json); @@ -234,10 +230,10 @@ main (gint argc, gchar *argv[]) } /* JSON to GVariant */ - for (i = 0; i < G_N_ELEMENTS (two_way_test_cases); i++) + for (guint i = 0; i < G_N_ELEMENTS (two_way_test_cases); i++) { - test_case = two_way_test_cases[i]; - test_name = g_strdup_printf ("/gvariant/from-json/%s", test_case.test_name); + TestCase test_case = two_way_test_cases[i]; + char *test_name = g_strdup_printf ("/gvariant/from-json/%s", test_case.test_name); g_test_add_data_func (test_name, &two_way_test_cases[i], test_json_to_gvariant); @@ -245,10 +241,10 @@ main (gint argc, gchar *argv[]) } /* JSON to GVariant one way tests */ - for (i = 0; i < G_N_ELEMENTS (json_to_gvariant_test_cases); i++) + for (guint i = 0; i < G_N_ELEMENTS (json_to_gvariant_test_cases); i++) { - test_case = json_to_gvariant_test_cases[i]; - test_name = g_strdup_printf ("/gvariant/from-json/%s", test_case.test_name); + TestCase test_case = json_to_gvariant_test_cases[i]; + char *test_name = g_strdup_printf ("/gvariant/from-json/%s", test_case.test_name); g_test_add_data_func (test_name, &json_to_gvariant_test_cases[i], test_json_to_gvariant); diff --git a/json-glib/tests/invalid.c b/json-glib/tests/invalid.c index 5197e9f..3cab2c2 100644 --- a/json-glib/tests/invalid.c +++ b/json-glib/tests/invalid.c @@ -252,11 +252,9 @@ int main (int argc, char *argv[]) { - int i; - g_test_init (&argc, &argv, NULL); - for (i = 0; i < n_test_invalid; i++) + for (guint i = 0; i < n_test_invalid; i++) { char *test_path = g_strconcat ("/invalid/json/", test_invalid[i].path, NULL); diff --git a/json-glib/tests/object.c b/json-glib/tests/object.c index b5cab1a..90e8bca 100644 --- a/json-glib/tests/object.c +++ b/json-glib/tests/object.c @@ -140,9 +140,7 @@ verify_foreach (JsonObject *object, } else { - int i; - - for (i = 0; i < G_N_ELEMENTS (type_verify); i++) + for (guint i = 0; i < G_N_ELEMENTS (type_verify); i++) { if (strcmp (member_name, type_verify[i].member_name) == 0) { diff --git a/json-glib/tests/parser.c b/json-glib/tests/parser.c index c6ee421..bd23798 100644 --- a/json-glib/tests/parser.c +++ b/json-glib/tests/parser.c @@ -189,7 +189,6 @@ test_empty (void) static void test_base_value (void) { - gint i; JsonParser *parser; parser = json_parser_new (); @@ -198,7 +197,7 @@ test_base_value (void) if (g_test_verbose ()) g_print ("checking json_parser_load_from_data with base-values...\n"); - for (i = 0; i < n_test_base_values; i++) + for (guint i = 0; i < n_test_base_values; i++) { GError *error = NULL; @@ -283,7 +282,6 @@ test_empty_array (void) static void test_simple_array (void) { - gint i; JsonParser *parser; parser = json_parser_new (); @@ -292,7 +290,7 @@ test_simple_array (void) if (g_test_verbose ()) g_print ("checking json_parser_load_from_data with simple arrays...\n"); - for (i = 0; i < n_test_simple_arrays; i++) + for (guint i = 0; i < n_test_simple_arrays; i++) { GError *error = NULL; @@ -347,7 +345,6 @@ test_simple_array (void) static void test_nested_array (void) { - gint i; JsonParser *parser; parser = json_parser_new (); @@ -356,7 +353,7 @@ test_nested_array (void) if (g_test_verbose ()) g_print ("checking json_parser_load_from_data with nested arrays...\n"); - for (i = 0; i < n_test_nested_arrays; i++) + for (guint i = 0; i < n_test_nested_arrays; i++) { GError *error = NULL; @@ -442,7 +439,6 @@ test_empty_object (void) static void test_simple_object (void) { - gint i; JsonParser *parser; parser = json_parser_new (); @@ -451,7 +447,7 @@ test_simple_object (void) if (g_test_verbose ()) g_print ("checking json_parser_load_from_data with simple objects...\n"); - for (i = 0; i < n_test_simple_objects; i++) + for (guint i = 0; i < n_test_simple_objects; i++) { GError *error = NULL; @@ -503,7 +499,6 @@ test_simple_object (void) static void test_nested_object (void) { - gint i; JsonParser *parser; parser = json_parser_new (); @@ -512,7 +507,7 @@ test_nested_object (void) if (g_test_verbose ()) g_print ("checking json_parser_load_from_data with nested objects...\n"); - for (i = 0; i < n_test_nested_objects; i++) + for (guint i = 0; i < n_test_nested_objects; i++) { GError *error = NULL; @@ -553,7 +548,6 @@ test_nested_object (void) static void test_assignment (void) { - gint i; JsonParser *parser; parser = json_parser_new (); @@ -562,7 +556,7 @@ test_assignment (void) if (g_test_verbose ()) g_print ("checking json_parser_load_from_data with assignments...\n"); - for (i = 0; i < n_test_assignments; i++) + for (guint i = 0; i < n_test_assignments; i++) { GError *error = NULL; @@ -595,7 +589,6 @@ test_assignment (void) static void test_unicode_escape (void) { - gint i; JsonParser *parser; parser = json_parser_new (); @@ -604,7 +597,7 @@ test_unicode_escape (void) if (g_test_verbose ()) g_print ("checking json_parser_load_from_data with unicode escape...\n"); - for (i = 0; i < n_test_unicode; i++) + for (guint i = 0; i < n_test_unicode; i++) { GError *error = NULL; diff --git a/json-glib/tests/path.c b/json-glib/tests/path.c index d674da3..2781ead 100644 --- a/json-glib/tests/path.c +++ b/json-glib/tests/path.c @@ -212,7 +212,7 @@ path_expressions_invalid (gconstpointer data) g_assert_false (json_path_compile (path, expr, &error)); - g_assert_error (error, JSON_PATH_ERROR, code); + g_assert_error (error, JSON_PATH_ERROR, (int) code); g_object_unref (path); g_clear_error (&error); @@ -268,7 +268,7 @@ int main (int argc, char *argv[]) { - int i, j; + guint i, j; g_test_init (&argc, &argv, NULL); g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id="); |