From 83d5006ee4f468c92073a5e7cc5ae7f440664e37 Mon Sep 17 00:00:00 2001 From: Soeren Sandmann Date: Thu, 30 Oct 2003 15:30:24 +0000 Subject: [PATCH] Make sure we actually return the index of a real item. (get_nth_item) Thu Oct 30 16:20:58 2003 Soeren Sandmann * gtk/gtktoolbar.c (logical_to_physical): Make sure we actually return the index of a real item. (get_nth_item) assert that the returned items is not a placeholder. (#125826, Marco Pesenti Gritti). --- ChangeLog | 7 +++++++ ChangeLog.pre-2-10 | 7 +++++++ ChangeLog.pre-2-4 | 7 +++++++ ChangeLog.pre-2-6 | 7 +++++++ ChangeLog.pre-2-8 | 7 +++++++ gtk/gtktoolbar.c | 21 +++++++++++++++------ 6 files changed, 50 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index dcabbba2e1..cabdbe2a3a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Thu Oct 30 16:20:58 2003 Soeren Sandmann + + * gtk/gtktoolbar.c (logical_to_physical): Make sure we actually + return the index of a real item. + (get_nth_item) assert that the returned items is not a + placeholder. (#125826, Marco Pesenti Gritti). + 2003-10-29 Federico Mena Quintero * gtk/gtkcellrendererseptext.c diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index dcabbba2e1..cabdbe2a3a 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,10 @@ +Thu Oct 30 16:20:58 2003 Soeren Sandmann + + * gtk/gtktoolbar.c (logical_to_physical): Make sure we actually + return the index of a real item. + (get_nth_item) assert that the returned items is not a + placeholder. (#125826, Marco Pesenti Gritti). + 2003-10-29 Federico Mena Quintero * gtk/gtkcellrendererseptext.c diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index dcabbba2e1..cabdbe2a3a 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,10 @@ +Thu Oct 30 16:20:58 2003 Soeren Sandmann + + * gtk/gtktoolbar.c (logical_to_physical): Make sure we actually + return the index of a real item. + (get_nth_item) assert that the returned items is not a + placeholder. (#125826, Marco Pesenti Gritti). + 2003-10-29 Federico Mena Quintero * gtk/gtkcellrendererseptext.c diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index dcabbba2e1..cabdbe2a3a 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,10 @@ +Thu Oct 30 16:20:58 2003 Soeren Sandmann + + * gtk/gtktoolbar.c (logical_to_physical): Make sure we actually + return the index of a real item. + (get_nth_item) assert that the returned items is not a + placeholder. (#125826, Marco Pesenti Gritti). + 2003-10-29 Federico Mena Quintero * gtk/gtkcellrendererseptext.c diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index dcabbba2e1..cabdbe2a3a 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,10 @@ +Thu Oct 30 16:20:58 2003 Soeren Sandmann + + * gtk/gtktoolbar.c (logical_to_physical): Make sure we actually + return the index of a real item. + (get_nth_item) assert that the returned items is not a + placeholder. (#125826, Marco Pesenti Gritti). + 2003-10-29 Federico Mena Quintero * gtk/gtkcellrendererseptext.c diff --git a/gtk/gtktoolbar.c b/gtk/gtktoolbar.c index 3536ed0118..3de4327605 100644 --- a/gtk/gtktoolbar.c +++ b/gtk/gtktoolbar.c @@ -1797,15 +1797,18 @@ logical_to_physical (GtkToolbar *toolbar, gint logical) g_assert (logical >= 0); physical = 0; - for (list = priv->content; list && logical > 0; list = list->next) + for (list = priv->content; list; list = list->next) { ToolbarContent *content = list->data; if (!content->is_placeholder) logical--; physical++; - } + if (!content->is_placeholder && logical == 0) + break; + } + g_assert (logical == 0); return physical; } @@ -2730,20 +2733,26 @@ gtk_toolbar_get_nth_item (GtkToolbar *toolbar, { GtkToolbarPrivate *priv; ToolbarContent *content; + gint n_items; g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL); if (!gtk_toolbar_check_new_api (toolbar)) return NULL; + + n_items = gtk_toolbar_get_n_items (toolbar); + + if (n < 0 || n >= n_items) + return NULL; priv = GTK_TOOLBAR_GET_PRIVATE (toolbar); content = g_list_nth_data (priv->content, logical_to_physical (toolbar, n)); - - if (content) - return content->item; - return NULL; + g_assert (content); + g_assert (!content->is_placeholder); + + return content->item; } /**