[gimp] libgimpconfig: fix conversion of negative int values in gimp_scanner_parse_float()



commit 71ad53ebcfe288ef2947e46997c37dad51690e2c
Author: Jacob Boerema <jgboerema gmail com>
Date:   Mon Sep 21 19:36:25 2020 -0400

    libgimpconfig: fix conversion of negative int values in gimp_scanner_parse_float()
    
    Negative int values were not correctly handled because value.v_int is unsigned
    causing a conversion to a large positive value.
    
    To fix this we cast it to gint64 first before making it negative.

 libgimpconfig/gimpscanner.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
---
diff --git a/libgimpconfig/gimpscanner.c b/libgimpconfig/gimpscanner.c
index 15dad89081..f168b1708e 100644
--- a/libgimpconfig/gimpscanner.c
+++ b/libgimpconfig/gimpscanner.c
@@ -594,22 +594,17 @@ gimp_scanner_parse_float (GimpScanner *scanner,
     }
   else if (g_scanner_peek_next_token (scanner) == G_TOKEN_INT)
     {
-      /* use a temp value because for whatever reason writing
+      /* v_int is unsigned so we need to cast to
        *
-       * *dest = -scanner->value.v_int;
-       *
-       * fails.
+       * gint64 first for negative values.
        */
-      gint64 int_value;
 
       g_scanner_get_next_token (scanner);
 
       if (negate)
-        int_value = -scanner->value.v_int;
+        *dest = - (gint64) scanner->value.v_int;
       else
-        int_value = scanner->value.v_int;
-
-      *dest = int_value;
+        *dest = scanner->value.v_int;
 
       return TRUE;
     }


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