[glib: 5/10] Fixing signedness warnings in glib/gdatetime.c



commit 3384ed3f7f2b6f36d552728b942d9d60848b3e9a
Author: Emmanuel Fleury <emmanuel fleury u-bordeaux fr>
Date:   Sat Jan 26 17:18:37 2019 +0100

    Fixing signedness warnings in glib/gdatetime.c
    
    glib/gdatetime.c: In function ‘get_iso8601_int’:
    glib/gdatetime.c:1142:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka 
‘int’} and ‘gsize’ {aka ‘long unsigned int’} [-Werror=sign-compare]
       for (i = 0; i < length; i++)
                     ^
    glib/gdatetime.c: In function ‘get_iso8601_seconds’:
    glib/gdatetime.c:1175:9: error: comparison of integer expressions of different signedness: ‘gint’ {aka 
‘int’} and ‘gsize’ {aka ‘long unsigned int’} [-Werror=sign-compare]
       if (i == length)
             ^~
    glib/gdatetime.c:1178:12: error: comparison of integer expressions of different signedness: ‘gint’ {aka 
‘int’} and ‘gsize’ {aka ‘long unsigned int’} [-Werror=sign-compare]
       for (; i < length; i++)
                ^
    In file included from glib/glibconfig.h:9,
                     from glib/gtypes.h:32,
                     from glib/gtimezone.h:27,
                     from glib/gdatetime.h:31,
                     from glib/gdatetime.c:62:
    glib/gdatetime.c: In function ‘initialize_alt_digits’:
    glib/gdatetime.c:2806:27: error: comparison of integer expressions of different signedness: ‘gsize’ {aka 
‘long unsigned int’} and ‘long int’ [-Werror=sign-compare]
           g_assert (digit_len < buffer + sizeof (buffer) - buffer_end);
                               ^
    glib/gmacros.h:455:25: note: in definition of macro ‘G_LIKELY’
     #define G_LIKELY(expr) (expr)
                             ^~~~
    glib/gdatetime.c:2806:7: note: in expansion of macro ‘g_assert’
           g_assert (digit_len < buffer + sizeof (buffer) - buffer_end);
           ^~~~~~~~

 glib/gdatetime.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
---
diff --git a/glib/gdatetime.c b/glib/gdatetime.c
index 9136ba233..8abf45a87 100644
--- a/glib/gdatetime.c
+++ b/glib/gdatetime.c
@@ -1134,7 +1134,8 @@ g_date_time_new_from_timeval_utc (const GTimeVal *tv)
 static gboolean
 get_iso8601_int (const gchar *text, gsize length, gint *value)
 {
-  gint i, v = 0;
+  gsize i;
+  guint v = 0;
 
   if (length < 1 || length > 4)
     return FALSE;
@@ -1155,7 +1156,7 @@ get_iso8601_int (const gchar *text, gsize length, gint *value)
 static gboolean
 get_iso8601_seconds (const gchar *text, gsize length, gdouble *value)
 {
-  gint i;
+  gsize i;
   gdouble divisor = 1, v = 0;
 
   if (length < 2)
@@ -2803,7 +2804,7 @@ initialize_alt_digits (void)
       if (digit == NULL)
         return NULL;
 
-      g_assert (digit_len < buffer + sizeof (buffer) - buffer_end);
+      g_assert (digit_len < (gsize) (buffer + sizeof (buffer) - buffer_end));
 
       alt_digits[i] = buffer_end;
       buffer_end = g_stpcpy (buffer_end, digit);


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