GtkStack: Fix a potential crash in gtk_stack_get_first_accessible_child
authorLukáš Tyrychtr <ltyrycht@redhat.com>
Mon, 29 May 2023 13:14:51 +0000 (15:14 +0200)
committerLukáš Tyrychtr <ltyrycht@redhat.com>
Mon, 29 May 2023 13:14:51 +0000 (15:14 +0200)
This one can occur when the stack has no pages.

gtk/gtkstack.c

index 59a3a0357ba0ac5df59b51d51f6261e82ecc4a22..dad20362503fffbe73fbecfffe88ac5b5c42d6f6 100644 (file)
@@ -809,9 +809,12 @@ gtk_stack_accessible_get_first_accessible_child (GtkAccessible *accessible)
 {
   GtkStack *stack = GTK_STACK (accessible);
   GtkStackPrivate *priv = gtk_stack_get_instance_private (stack);
-  GtkStackPage *page = g_ptr_array_index (priv->children, 0);
+  GtkAccessible *page_accessible = NULL;
 
-  return GTK_ACCESSIBLE (g_object_ref (page));
+  if (priv->children->len > 0)
+    page_accessible = GTK_ACCESSIBLE (g_object_ref (g_ptr_array_index (priv->children, 0)));
+  
+  return page_accessible;
 }
 
 static void