[glib: 6/8] Fix signedness warnings in tests/gio-test.c




commit 1d02b96655710a207173d26c726e8faeae9a06ba
Author: Emmanuel Fleury <emmanuel fleury gmail com>
Date:   Fri Nov 20 22:42:12 2020 +0100

    Fix signedness warnings in tests/gio-test.c
    
    tests/gio-test.c: In function ‘recv_message’:
    tests/gio-test.c:172:24: error: comparison of unsigned expression in ‘>= 0’ is always true
      172 |       g_assert (nbytes >= 0 && nbytes < BUFSIZE);
          |                        ^~
    glib/gmacros.h:941:25: note: in definition of macro ‘G_LIKELY’
      941 | #define G_LIKELY(expr) (expr)
          |                         ^~~~
    tests/gio-test.c:172:7: note: in expansion of macro ‘g_assert’
      172 |       g_assert (nbytes >= 0 && nbytes < BUFSIZE);
          |       ^~~~~~~~
    tests/gio-test.c:188:18: error: comparison of integer expressions of different signedness: ‘int’ and 
‘guint’ {aka ‘unsigned int’}
      188 |    for (j = 0; j < nbytes; j++)
          |                  ^
    tests/gio-test.c:189:30: error: comparison of integer expressions of different signedness: ‘char’ and 
‘guint’ {aka ‘unsigned int’}
      189 |             g_assert (buf[j] == ' ' + ((nbytes + j) % 95));
          |                              ^~
    glib/gmacros.h:941:25: note: in definition of macro ‘G_LIKELY’
      941 | #define G_LIKELY(expr) (expr)
          |                         ^~~~
    tests/gio-test.c:189:13: note: in expansion of macro ‘g_assert’
      189 |             g_assert (buf[j] == ' ' + ((nbytes + j) % 95));
          |             ^~~~~~~~

 tests/gio-test.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
---
diff --git a/tests/gio-test.c b/tests/gio-test.c
index deffa4d09..6c40632b3 100644
--- a/tests/gio-test.c
+++ b/tests/gio-test.c
@@ -130,7 +130,8 @@ recv_message (GIOChannel  *channel,
       char buf[BUFSIZE];
       guint nbytes;
       guint nb;
-      int i, j, seq;
+      guint j;
+      int i, seq;
       GIOError error;
       
       error = read_all (fd, channel, (gchar *) &seq, sizeof (seq), &nb);
@@ -169,7 +170,7 @@ recv_message (GIOChannel  *channel,
       g_assert (nb == sizeof (nbytes));
 
       g_assert_cmpint (nbytes, <, BUFSIZE);
-      g_assert (nbytes >= 0 && nbytes < BUFSIZE);
+      g_assert (nbytes < BUFSIZE);
       g_debug ("gio-test: ...from %d: %d bytes", fd, nbytes);
       if (nbytes > 0)
        {
@@ -186,7 +187,7 @@ recv_message (GIOChannel  *channel,
            }
       
          for (j = 0; j < nbytes; j++)
-            g_assert (buf[j] == ' ' + ((nbytes + j) % 95));
+            g_assert (buf[j] == ' ' + (char) ((nbytes + j) % 95));
          g_debug ("gio-test: ...from %d: OK", fd);
        }
     }


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