[gtk/ebassi/for-master: 2/3] Make the inout argument logic clearer




commit 786e9d351cce774e5d5baa4fac92603b25c6e50a
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Tue Jan 26 12:54:53 2021 +0000

    Make the inout argument logic clearer
    
    It's easy to misread a `+=`.

 gdk/gdksurface.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c
index 52b45edfd1..aaeb6d21b4 100644
--- a/gdk/gdksurface.c
+++ b/gdk/gdksurface.c
@@ -2980,9 +2980,13 @@ gdk_surface_translate_coordinates (GdkSurface *from,
                                    double     *x,
                                    double     *y)
 {
+  double in_x, in_y, out_x, out_y;
   int x1, y1, x2, y2;
   GdkSurface *f, *t;
 
+  in_x = *x;
+  in_y = *y;
+
   x1 = 0;
   y1 = 0;
   f = from;
@@ -3006,8 +3010,11 @@ gdk_surface_translate_coordinates (GdkSurface *from,
   if (f != t)
     return FALSE;
 
-  *x += x1 - x2;
-  *y += y1 - y2;
+  out_x = in_x + (x1 - x2);
+  out_y = in_y + (y1 - y2);
+
+  *x = out_x;
+  *y = out_y;
 
   return TRUE;
 }


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