[gimp/gimp-2-10] Issue #4172 - Gimp doesn't store negative values between sessions (Text Tool)



commit ef17d1a5e52670b41106418bc163ea7c90cf45dc
Author: Ell <ell_se yahoo com>
Date:   Sun Nov 3 13:38:24 2019 +0200

    Issue #4172 - Gimp doesn't store negative values between sessions (Text Tool)
    
    In gimp_config_deserialize_fundamental(), cast integer token values
    to the target value type *before* negating them, to avoid
    performing unsigned negation, which can result in a positive value
    when cast to the target value type (in particular, when the target
    value type is float/double).
    
    (cherry picked from commit 38fff3b6b3653f18a11510749aea89c162dca253)

 libgimpconfig/gimpconfig-deserialize.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)
---
diff --git a/libgimpconfig/gimpconfig-deserialize.c b/libgimpconfig/gimpconfig-deserialize.c
index 5d7707c779..d2479c1b96 100644
--- a/libgimpconfig/gimpconfig-deserialize.c
+++ b/libgimpconfig/gimpconfig-deserialize.c
@@ -478,8 +478,8 @@ gimp_config_deserialize_fundamental (GValue     *value,
 
     case G_TYPE_INT:
       g_value_set_int (value, (negate ?
-                               - scanner->value.v_int64 :
-                               scanner->value.v_int64));
+                               - (gint) scanner->value.v_int64 :
+                                 (gint) scanner->value.v_int64));
       break;
     case G_TYPE_UINT:
       g_value_set_uint (value, scanner->value.v_int64);
@@ -487,8 +487,8 @@ gimp_config_deserialize_fundamental (GValue     *value,
 
     case G_TYPE_LONG:
       g_value_set_long (value, (negate ?
-                                - scanner->value.v_int64 :
-                                scanner->value.v_int64));
+                                - (glong) scanner->value.v_int64 :
+                                  (glong) scanner->value.v_int64));
       break;
     case G_TYPE_ULONG:
       g_value_set_ulong (value, scanner->value.v_int64);
@@ -496,8 +496,8 @@ gimp_config_deserialize_fundamental (GValue     *value,
 
     case G_TYPE_INT64:
       g_value_set_int64 (value, (negate ?
-                                 - scanner->value.v_int64 :
-                                 scanner->value.v_int64));
+                                 - (gint64) scanner->value.v_int64 :
+                                   (gint64) scanner->value.v_int64));
       break;
     case G_TYPE_UINT64:
       g_value_set_uint64 (value, scanner->value.v_int64);
@@ -506,19 +506,23 @@ gimp_config_deserialize_fundamental (GValue     *value,
     case G_TYPE_FLOAT:
       if (next_token == G_TOKEN_FLOAT)
         g_value_set_float (value, negate ?
-                           - scanner->value.v_float : scanner->value.v_float);
+                           - scanner->value.v_float :
+                             scanner->value.v_float);
       else
         g_value_set_float (value, negate ?
-                           - scanner->value.v_int : scanner->value.v_int);
+                           - (gfloat) scanner->value.v_int :
+                             (gfloat) scanner->value.v_int);
       break;
 
     case G_TYPE_DOUBLE:
       if (next_token == G_TOKEN_FLOAT)
         g_value_set_double (value, negate ?
-                            - scanner->value.v_float: scanner->value.v_float);
+                            - scanner->value.v_float:
+                              scanner->value.v_float);
       else
         g_value_set_double (value, negate ?
-                            - scanner->value.v_int: scanner->value.v_int);
+                            - (gdouble) scanner->value.v_int:
+                              (gdouble) scanner->value.v_int);
       break;
 
     default:


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