gtkstack: fix null pointer dereference

The gtk_stack_snapshot_slide() function dereferences the
last_visible_child pointer without proper != NULL ckeck. This might
result in NULL pointer dereference and crash if last_visible_child is
invalid.

Add a != NULL check before dereferencing the pointer.

cherry-picked from https://gitlab.gnome.org/GNOME/gtk/merge_requests/361
This commit is contained in:
Hugo Lefeuvre 2018-09-26 16:59:59 -04:00 committed by Daniel Boles
parent b10cde7bdc
commit adbaee796d

View File

@ -2088,12 +2088,14 @@ gtk_stack_draw_slide (GtkWidget *widget,
x += priv->last_visible_surface_allocation.x;
y += priv->last_visible_surface_allocation.y;
if (priv->last_visible_child != NULL)
{
if (gtk_widget_get_valign (priv->last_visible_child->widget) == GTK_ALIGN_END &&
priv->last_visible_widget_height > allocation.height)
y -= priv->last_visible_widget_height - allocation.height;
else if (gtk_widget_get_valign (priv->last_visible_child->widget) == GTK_ALIGN_CENTER)
y -= (priv->last_visible_widget_height - allocation.height) / 2;
}
cairo_save (cr);
cairo_set_source_surface (cr, priv->last_visible_surface, x, y);