From 5fec11245307347082bc9ccae8d495a37a40abb0 Mon Sep 17 00:00:00 2001 From: Emmanuel Fleury Date: Wed, 18 Nov 2020 19:53:33 +0100 Subject: [PATCH 1/7] Fix signedness warning in gio/giomodule.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gio/giomodule.c: In function ‘print_help’: glib/gmacros.h:806:26: error: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} 806 | #define MAX(a, b) (((a) > (b)) ? (a) : (b)) | ^ ../glib.git/gio/giomodule.c:733:19: note: in expansion of macro ‘MAX’ 733 | width = MAX (width, strlen (g_io_extension_get_name (extension))); | ^~~ --- gio/giomodule.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gio/giomodule.c b/gio/giomodule.c index a2909a8ef..d3b5e482a 100644 --- a/gio/giomodule.c +++ b/gio/giomodule.c @@ -731,7 +731,7 @@ print_help (const char *envvar, { GList *l; GIOExtension *extension; - int width = 0; + gsize width = 0; for (l = g_io_extension_point_get_extensions (ep); l; l = l->next) { @@ -743,7 +743,9 @@ print_help (const char *envvar, { extension = l->data; - g_print (" %*s - %d\n", width, g_io_extension_get_name (extension), g_io_extension_get_priority (extension)); + g_print (" %*s - %d\n", (int) MIN (width, G_MAXINT), + g_io_extension_get_name (extension), + g_io_extension_get_priority (extension)); } } } From 1f23770bc30980cf1e4046a24b4f39de6ea8c1ed Mon Sep 17 00:00:00 2001 From: Emmanuel Fleury Date: Wed, 18 Nov 2020 20:07:34 +0100 Subject: [PATCH 2/7] Fix signedness warning in gio/gunixsocketaddress.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gio/gunixsocketaddress.c: In function ‘g_unix_socket_address_to_native’: gio/gunixsocketaddress.c:217:15: error: comparison of integer expressions of different signedness: ‘gsize’ {aka ‘long unsigned int’} and ‘gssize’ {aka ‘long int’} 217 | if (destlen < socklen) | ^ --- gio/gunixsocketaddress.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gio/gunixsocketaddress.c b/gio/gunixsocketaddress.c index 0ab1a62e9..69204e9b9 100644 --- a/gio/gunixsocketaddress.c +++ b/gio/gunixsocketaddress.c @@ -214,7 +214,8 @@ g_unix_socket_address_to_native (GSocketAddress *address, gssize socklen; socklen = g_unix_socket_address_get_native_size (address); - if (destlen < socklen) + g_assert (socklen >= 0); + if (destlen < (gsize) socklen) { g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NO_SPACE, _("Not enough space for socket address")); From 0214d892ba6652eb2cd6835f7e771b18f6ce042b Mon Sep 17 00:00:00 2001 From: Emmanuel Fleury Date: Wed, 18 Nov 2020 20:41:48 +0100 Subject: [PATCH 3/7] Fix unecessary assert with always true assertions in gio/gresource-tool.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gio/gresource-tool.c: In function ‘elf_foreach_resource_section’: gio/gresource-tool.c:190:22: error: comparison of unsigned expression in ‘>= 0’ is always true 190 | g_assert (shstrndx >= 0); | ^~ gio/gresource-tool.c:193:19: error: comparison of unsigned expression in ‘>= 0’ is always true 193 | g_assert (shnum >= 0); | ^~ --- gio/gresource-tool.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gio/gresource-tool.c b/gio/gresource-tool.c index 1914c5228..aa718974e 100644 --- a/gio/gresource-tool.c +++ b/gio/gresource-tool.c @@ -180,17 +180,18 @@ elf_foreach_resource_section (Elf *elf, SectionCallback callback, gpointer data) { + int ret; size_t shstrndx, shnum; size_t scnidx; Elf_Scn *scn; GElf_Shdr *shdr, shdr_mem; const gchar *section_name; - elf_getshdrstrndx (elf, &shstrndx); - g_assert (shstrndx >= 0); + ret = elf_getshdrstrndx (elf, &shstrndx); + g_assert (ret == 0); - elf_getshdrnum (elf, &shnum); - g_assert (shnum >= 0); + ret = elf_getshdrnum (elf, &shnum); + g_assert (ret == 0); for (scnidx = 1; scnidx < shnum; scnidx++) { From a7d3ecca77dc4dffc2bb540a407203e8bfbf6fca Mon Sep 17 00:00:00 2001 From: Emmanuel Fleury Date: Wed, 18 Nov 2020 20:59:37 +0100 Subject: [PATCH 4/7] Fix signedness warning in gio/gsettings-tool.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gio/gsettings-tool.c: In function ‘gsettings_list_children’: gio/gsettings-tool.c:199:30: error: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘gint’ {aka ‘int’} 199 | if (strlen (children[i]) > max) | ^ --- gio/gsettings-tool.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/gio/gsettings-tool.c b/gio/gsettings-tool.c index 3096f9d9b..7559a6b1b 100644 --- a/gio/gsettings-tool.c +++ b/gio/gsettings-tool.c @@ -191,13 +191,16 @@ static void gsettings_list_children (void) { gchar **children; - gint max = 0; + gsize max = 0; gint i; children = g_settings_list_children (global_settings); for (i = 0; children[i]; i++) - if (strlen (children[i]) > max) - max = strlen (children[i]); + { + gsize len = strlen (children[i]); + if (len > max) + max = len; + } for (i = 0; children[i]; i++) { @@ -212,9 +215,11 @@ gsettings_list_children (void) NULL); if (g_settings_schema_get_path (schema) != NULL) - g_print ("%-*s %s\n", max, children[i], g_settings_schema_get_id (schema)); + g_print ("%-*s %s\n", (int) MIN (max, G_MAXINT), children[i], + g_settings_schema_get_id (schema)); else - g_print ("%-*s %s:%s\n", max, children[i], g_settings_schema_get_id (schema), path); + g_print ("%-*s %s:%s\n", (int) MIN (max, G_MAXINT), children[i], + g_settings_schema_get_id (schema), path); g_object_unref (child); g_settings_schema_unref (schema); From 8bcb2b9e7632d5e1e804dfbb545d7b58dd72450c Mon Sep 17 00:00:00 2001 From: Emmanuel Fleury Date: Tue, 17 Nov 2020 23:40:22 +0100 Subject: [PATCH 5/7] Fix several signedness warnings in gio/tests/contexts.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gio/tests/contexts.c: In function ‘test_context_specific_emit’: gio/tests/contexts.c:379:21: error: comparison of integer expressions of different signedness: ‘guint’ {aka ‘unsigned int’} and ‘gint32’ {aka ‘int’} 379 | for (i = 0; i < g_test_rand_int_range (1, 5); i++) | ^ gio/tests/contexts.c:383:55: error: comparison of integer expressions of different signedness: ‘int’ and ‘guint’ {aka ‘unsigned int’} 383 | while (g_atomic_int_get (&observed_values[i]) != n) | ^~ gio/tests/contexts.c:387:41: error: comparison of integer expressions of different signedness: ‘gint64’ {aka ‘long int’} and ‘guint64’ {aka ‘long unsigned int’} 387 | if (g_get_monotonic_time () > expiry) | ^ --- gio/tests/contexts.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gio/tests/contexts.c b/gio/tests/contexts.c index c6dc26111..3b64c7622 100644 --- a/gio/tests/contexts.c +++ b/gio/tests/contexts.c @@ -360,7 +360,8 @@ test_context_specific_emit (void) { GThread *threads[N_THREADS]; gboolean exited = FALSE; - guint i, n; + gsize i; + gint k, n; for (i = 0; i < N_THREADS; i++) threads[i] = g_thread_new ("test", test_emit_thread, &observed_values[i]); @@ -368,7 +369,7 @@ test_context_specific_emit (void) /* make changes and ensure that they are observed */ for (n = 0; n < 1000; n++) { - guint64 expiry; + gint64 expiry; /* don't burn CPU forever */ expiry = g_get_monotonic_time () + 10 * G_TIME_SPAN_SECOND; @@ -376,7 +377,7 @@ test_context_specific_emit (void) g_atomic_int_set (¤t_value, n); /* wake them to notice */ - for (i = 0; i < g_test_rand_int_range (1, 5); i++) + for (k = 0; k < g_test_rand_int_range (1, 5); k++) g_context_specific_group_emit (&group, g_signal_lookup ("changed", per_thread_thing_get_type ())); for (i = 0; i < N_THREADS; i++) From 88253f171ce3e65ed939f79f47e102a45e358b3b Mon Sep 17 00:00:00 2001 From: Emmanuel Fleury Date: Tue, 17 Nov 2020 23:43:09 +0100 Subject: [PATCH 6/7] Fix signedness warning in gio/tests/contenttype.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gio/tests/contenttype.c: In function ‘test_tree’: gio/tests/contenttype.c:337:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’ 337 | for (i = 0; i < G_N_ELEMENTS (tests); i++) | ^ --- gio/tests/contenttype.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gio/tests/contenttype.c b/gio/tests/contenttype.c index 71e8b0df6..f2faaf68d 100644 --- a/gio/tests/contenttype.c +++ b/gio/tests/contenttype.c @@ -363,7 +363,7 @@ test_tree (void) const gchar *path; GFile *file; gchar **types; - gint i; + gsize i; #ifdef __APPLE__ g_test_skip ("The OSX backend does not implement g_content_type_guess_for_tree()"); From eafc764bb2bac85cf7b8a2b64f6daeb60d0d43c6 Mon Sep 17 00:00:00 2001 From: Emmanuel Fleury Date: Tue, 17 Nov 2020 23:46:41 +0100 Subject: [PATCH 7/7] Fix several signedness warnings in gio/tests/converter-stream.c:main() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gio/tests/converter-stream.c: In function ‘main’: gio/tests/converter-stream.c:1220:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’ 1220 | for (i = 0; i < G_N_ELEMENTS (compressor_tests); i++) | ^ gio/tests/converter-stream.c:1223:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’ 1223 | for (i = 0; i < G_N_ELEMENTS (truncation_tests); i++) | ^ gio/tests/converter-stream.c:1226:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’ 1226 | for (i = 0; i < G_N_ELEMENTS (charset_tests); i++) | ^ --- gio/tests/converter-stream.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gio/tests/converter-stream.c b/gio/tests/converter-stream.c index 8bec95c76..45fb6a673 100644 --- a/gio/tests/converter-stream.c +++ b/gio/tests/converter-stream.c @@ -1207,7 +1207,7 @@ main (int argc, { "/converter-input-stream/charset/fallbacks", "UTF-8", "Some characters just don't fit into latin1: πא", "ISO-8859-1", "Some characters just don't fit into latin1: \\CF\\80\\D7\\90", 4 }, }; - gint i; + gsize i; g_test_init (&argc, &argv, NULL);