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



commit 404761cf743606f2529e91b8f81314a0f0e5dd6a
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 c35ed35..e196a35 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -2296,6 +2296,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);
 }
 
@@ -2997,18 +3000,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]