From: G.Willems Date: Sat, 24 Jun 2023 01:05:37 +0000 (+0200) Subject: stack: fix pages list bounds check X-Git-Tag: archive/raspbian/4.12.3+ds-1+rpi1~1^2^2^2~22^2~1^2~101^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=91d302a2015719bba5f6bca26212475f777d85a7;p=gtk4.git stack: fix pages list bounds check Fix integer underflow when children->len is 0. Add missing bounds check in select_item() --- diff --git a/gtk/gtkstack.c b/gtk/gtkstack.c index dad2036250..b56d24d9c0 100644 --- a/gtk/gtkstack.c +++ b/gtk/gtkstack.c @@ -617,8 +617,7 @@ gtk_stack_pages_get_item (GListModel *model, GtkStackPrivate *priv = gtk_stack_get_instance_private (pages->stack); GtkStackPage *page; - - if (position > priv->children->len - 1) + if (position >= priv->children->len) return NULL; page = g_ptr_array_index (priv->children, position); @@ -642,7 +641,7 @@ gtk_stack_pages_is_selected (GtkSelectionModel *model, GtkStackPrivate *priv = gtk_stack_get_instance_private (pages->stack); GtkStackPage *page; - if (position > priv->children->len - 1) + if (position >= priv->children->len) return FALSE; page = g_ptr_array_index (priv->children, position); @@ -664,6 +663,9 @@ gtk_stack_pages_select_item (GtkSelectionModel *model, GtkStackPrivate *priv = gtk_stack_get_instance_private (pages->stack); GtkStackPage *page; + if (position >= priv->children->len) + return FALSE; + page = g_ptr_array_index (priv->children, position); set_visible_child (pages->stack, page, priv->transition_type, priv->transition_duration); @@ -813,7 +815,7 @@ gtk_stack_accessible_get_first_accessible_child (GtkAccessible *accessible) if (priv->children->len > 0) page_accessible = GTK_ACCESSIBLE (g_object_ref (g_ptr_array_index (priv->children, 0))); - + return page_accessible; }