[gtk+/multitouch: 24/123] scrolledwindow: Don't crash on 0-sized motion buffer



commit a543470b3b53a47a1305c2d0179e9636e3bb3d8f
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Nov 1 12:49:18 2011 +0100

    scrolledwindow: Don't crash on 0-sized motion buffer

 gtk/gtkscrolledwindow.c |   26 ++++++++++++++++----------
 1 files changed, 16 insertions(+), 10 deletions(-)
---
diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c
index a90ed2c..95d1126 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -2301,6 +2301,9 @@ motion_event_list_last (MotionEventList *motion_events)
 {
   guint n_motions = MIN (motion_events->len, motion_events->buffer->len);
 
+  if (n_motions == 0)
+    return NULL;
+
   return &g_array_index (motion_events->buffer, MotionData, n_motions - 1);
 }
 
@@ -3002,18 +3005,21 @@ gtk_scrolled_window_motion_notify_event (GtkWidget *widget,
 
   motion = motion_event_list_last (&priv->motion_events);
 
-  hadjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
-  if (hadjustment)
+  if (motion)
     {
-      dx = (motion->x - event->x_root) + gtk_adjustment_get_value (hadjustment);
-      gtk_adjustment_set_value (hadjustment, dx);
-    }
+      hadjustment = gtk_range_get_adjustment (GTK_RANGE (priv->hscrollbar));
+      if (hadjustment)
+        {
+          dx = (motion->x - event->x_root) + gtk_adjustment_get_value (hadjustment);
+          gtk_adjustment_set_value (hadjustment, dx);
+        }
 
-  vadjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
-  if (vadjustment)
-    {
-      dy = (motion->y - event->y_root) + gtk_adjustment_get_value (vadjustment);
-      gtk_adjustment_set_value (vadjustment, dy);
+      vadjustment = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
+      if (vadjustment)
+        {
+          dy = (motion->y - event->y_root) + gtk_adjustment_get_value (vadjustment);
+          gtk_adjustment_set_value (vadjustment, dy);
+        }
     }
 
   motion = motion_event_list_append (&priv->motion_events);



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