GNOME Bugzilla – Bug 682080
Gtk:ERROR:gtktoolbar.c:2271:logical_to_physical: assertion failed: (logical == 0)
Last modified: 2016-05-19 12:38:30 UTC
This small testcase triggers this assertion in gtk+: #include <gtk/gtk.h> void main (int argc, char **argv) { GtkWidget *toolbar; GtkToolItem *button; gtk_init (&argc, &argv); toolbar = gtk_toolbar_new (); button = gtk_toggle_tool_button_new (); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), button, 1); } It's coming from: static gint logical_to_physical (GtkToolbar *toolbar, gint logical) { GtkToolbarPrivate *priv = toolbar->priv; GList *list; gint physical; g_assert (logical >= 0); physical = 0; for (list = priv->content; list; list = list->next) { ToolbarContent *content = list->data; if (!toolbar_content_is_placeholder (content)) { if (logical == 0) break; logical--; } physical++; } g_assert (logical == 0); return physical; } This function asserts if the toolbar contains less 'logical' elements. The test case is trying to insert an item at position 1 in an empty toolbar, so the assert is triggered. Maybe a g_return_val_if_fail (logical == 0, physical); would be better than the assert?
Still occurring with latest stable gtk+ with the same test case, setting 'version' to 3.20.x.
I feel like a simple position = MIN (position, g_list_length (priv->content)) in gtk_toolbar_insert would be the correct thing to do in any case since values greater than that have no meaning anyway. I don't usually use toolbars though, but I'm attaching a patch anyway.
Created attachment 327604 [details] [review] toolbar: Use g_assert_cmpint instead of just g_assert
Created attachment 327605 [details] [review] toolbar: Limit item position to number of contained elements
Review of attachment 327605 [details] [review]: looks fine to me
Review of attachment 327604 [details] [review]: I don't like mixing fancy-printing-asserts-for-tests with production code.
Pushed as 63be0deb0f112c354d3b4d2bbee44e6512d24358.