[glib: 22/25] Fixing various warnings in glib/gvariant-parser.c



commit a7aac03eada6e7a8334801ae72e77e0b020e2f93
Author: Emmanuel Fleury <emmanuel fleury u-bordeaux fr>
Date:   Thu Feb 14 10:56:21 2019 +0100

    Fixing various warnings in glib/gvariant-parser.c
    
    glib/gvariant-parser.c: In function ‘number_get_value’:
    glib/gvariant-parser.c:1924:46: error: operand of ?: changes signedness from ‘int’ to ‘guint64’ {aka 
‘long unsigned int’} due to unsignedness of other operand [-Werror=sign-compare]
           return g_variant_new_int16 (negative ? -((gint16) abs_val) : abs_val);
                                                 ^~~~~~~~~~~~~~~~~~~
    glib/gvariant-parser.c:1934:46: error: operand of ?: changes signedness from ‘int’ to ‘guint64’ {aka 
‘long unsigned int’} due to unsignedness of other operand [-Werror=sign-compare]
           return g_variant_new_int32 (negative ? -((gint32) abs_val) : abs_val);
                                                  ^~~~~~~~~~~~~~~~~~~
    glib/gvariant-parser.c:1944:46: error: operand of ?: changes signedness from ‘long int’ to ‘guint64’ {aka 
‘long unsigned int’} due to unsignedness of other operand [-Werror=sign-compare]
           return g_variant_new_int64 (negative ? -((gint64) abs_val) : abs_val);
                                                      ^~~~~~~~~~~~~~~~~~~
    glib/gvariant-parser.c:1954:47: error: operand of ?: changes signedness from ‘int’ to ‘guint64’ {aka 
‘long unsigned int’} due to unsignedness of other operand [-Werror=sign-compare]
           return g_variant_new_handle (negative ? -((gint32) abs_val) : abs_val);
                                                       ^~~~~~~~~~~~~~~~~~~
    glib/gvariant-parser.c: In function ‘g_variant_parse_error_print_context’:
    glib/gvariant-parser.c:2785:17: error: comparison of integer expressions of different signedness: ‘gint’ 
{aka ‘int’} and ‘size_t’ {aka ‘long unsigned int’} [-Werror=sign-compare]
           if (point >= strlen (source_str))
                     ^~

 glib/gvariant-parser.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)
---
diff --git a/glib/gvariant-parser.c b/glib/gvariant-parser.c
index c73b7dc18..589fe3f4f 100644
--- a/glib/gvariant-parser.c
+++ b/glib/gvariant-parser.c
@@ -1938,7 +1938,8 @@ number_get_value (AST                 *ast,
         return number_overflow (ast, type, error);
       if (negative && abs_val > G_MAXINT16)
         return g_variant_new_int16 (G_MININT16);
-      return g_variant_new_int16 (negative ? -((gint16) abs_val) : abs_val);
+      return g_variant_new_int16 (negative ?
+                                  -((gint16) abs_val) : ((gint16) abs_val));
 
     case 'q':
       if (negative || abs_val > G_MAXUINT16)
@@ -1950,7 +1951,8 @@ number_get_value (AST                 *ast,
         return number_overflow (ast, type, error);
       if (negative && abs_val > G_MAXINT32)
         return g_variant_new_int32 (G_MININT32);
-      return g_variant_new_int32 (negative ? -((gint32) abs_val) : abs_val);
+      return g_variant_new_int32 (negative ?
+                                  -((gint32) abs_val) : ((gint32) abs_val));
 
     case 'u':
       if (negative || abs_val > G_MAXUINT32)
@@ -1962,7 +1964,8 @@ number_get_value (AST                 *ast,
         return number_overflow (ast, type, error);
       if (negative && abs_val > G_MAXINT64)
         return g_variant_new_int64 (G_MININT64);
-      return g_variant_new_int64 (negative ? -((gint64) abs_val) : abs_val);
+      return g_variant_new_int64 (negative ?
+                                  -((gint64) abs_val) : ((gint64) abs_val));
 
     case 't':
       if (negative)
@@ -1974,7 +1977,8 @@ number_get_value (AST                 *ast,
         return number_overflow (ast, type, error);
       if (negative && abs_val > G_MAXINT32)
         return g_variant_new_handle (G_MININT32);
-      return g_variant_new_handle (negative ? -((gint32) abs_val) : abs_val);
+      return g_variant_new_handle (negative ?
+                                   -((gint32) abs_val) : ((gint32) abs_val));
 
     default:
       return ast_type_error (ast, type, error);
@@ -2630,7 +2634,7 @@ g_variant_builder_add_parsed (GVariantBuilder *builder,
 static gboolean
 parse_num (const gchar *num,
            const gchar *limit,
-           gint        *result)
+           guint       *result)
 {
   gchar *endptr;
   gint64 bignum;
@@ -2643,7 +2647,7 @@ parse_num (const gchar *num,
   if (bignum < 0 || bignum > G_MAXINT)
     return FALSE;
 
-  *result = bignum;
+  *result = (guint) bignum;
 
   return TRUE;
 }
@@ -2799,7 +2803,7 @@ g_variant_parse_error_print_context (GError      *error,
 
   if (dash == NULL || colon < dash)
     {
-      gint point;
+      guint point;
 
       /* we have a single point */
       if (!parse_num (error->message, colon, &point))
@@ -2817,7 +2821,7 @@ g_variant_parse_error_print_context (GError      *error,
       /* We have one or two ranges... */
       if (comma && comma < colon)
         {
-          gint start1, end1, start2, end2;
+          guint start1, end1, start2, end2;
           const gchar *dash2;
 
           /* Two ranges */
@@ -2833,7 +2837,7 @@ g_variant_parse_error_print_context (GError      *error,
         }
       else
         {
-          gint start, end;
+          guint start, end;
 
           /* One range */
           if (!parse_num (error->message, dash, &start) || !parse_num (dash + 1, colon, &end))


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