From 7392ac6fcf853299d9c16fbf2c89dd337b0bbd44 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Wed, 18 Aug 2021 15:51:19 -0700 Subject: [PATCH] Prevent running off the end of the GncOptionUI widget's parent tree. --- gnucash/gnome-utils/dialog-options.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/gnucash/gnome-utils/dialog-options.cpp b/gnucash/gnome-utils/dialog-options.cpp index 7702c5485c..fddf9400e5 100644 --- a/gnucash/gnome-utils/dialog-options.cpp +++ b/gnucash/gnome-utils/dialog-options.cpp @@ -228,9 +228,16 @@ gnc_option_get_gtk_widget (const GncOption* option) static void dialog_changed_internal (GtkWidget *widget, bool sensitive) { - while (widget && !GTK_IS_WINDOW(widget)) - widget = gtk_widget_get_parent(widget); - if (!widget) return; + g_return_if_fail(widget); + while (TRUE) + { + auto new_widget = gtk_widget_get_parent(widget); + if (new_widget && GTK_IS_WIDGET(new_widget) && + GTK_IS_WINDOW(new_widget)) + widget = new_widget; + else + break; + } /* find the ok and cancel buttons, we know where they will be so do it this way as opposed to using gtk_container_foreach, much less iteration */