Skip to content

Commit

Permalink
Refactor widget packing
Browse files Browse the repository at this point in the history
This fixes a cppcheck 2.2+ confusion about uninitialized widgets array
and also makes the code a bit more readable.
Closes geany#1014.
  • Loading branch information
eht16 committed Oct 17, 2020
1 parent 9cd01e5 commit b747f19
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions debugger/src/tpage.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,22 +139,23 @@ void tpage_pack_widgets(gboolean tabbed)
{
/* root box */
GtkWidget *root = NULL, *oldroot = NULL;
GtkWidget **widget = NULL;
GList *children = gtk_container_get_children(GTK_CONTAINER(tab_target));
if (children)
{
int i;
int i = 0;

oldroot = (GtkWidget*)children->data;

/* unparent widgets */
i = 0;
while (widgets[i])
do
{
g_object_ref(*widgets[i]);
gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(*widgets[i])), *widgets[i]);
widget = widgets[i];
g_object_ref(widget);
gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(*widget)), *widget);
i++;
}
} while (widget);

g_list_free(children);
}

Expand Down Expand Up @@ -266,11 +267,12 @@ void tpage_pack_widgets(gboolean tabbed)
if (oldroot)
{
int i = 0;
while (widgets[i])
do
{
widget = widgets[i];
g_object_unref(*widgets[i]);
i++;
}
} while (widget);
gtk_container_remove(GTK_CONTAINER(tab_target), oldroot);
}

Expand Down

0 comments on commit b747f19

Please sign in to comment.