[glib: 4/8] Fix signedness warning in gio/gsettings-tool.c




commit a7d3ecca77dc4dffc2bb540a407203e8bfbf6fca
Author: Emmanuel Fleury <emmanuel fleury gmail com>
Date:   Wed Nov 18 20:59:37 2020 +0100

    Fix signedness warning in gio/gsettings-tool.c
    
    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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]