diff options
author | Daniel Boles <dboles@src.gnome.org> | 2017-08-07 18:32:57 +0100 |
---|---|---|
committer | Daniel Boles <dboles@src.gnome.org> | 2017-08-07 19:21:09 +0100 |
commit | 23b6699ec35d069c3f4a7b3a90bb5881740aab8e (patch) | |
tree | b187601267e076f5c4f340be4b02eac25af47c2d /gtk/gtkcontainer.c | |
parent | c4865bed432073ff8ed0551e16169c57f5633b32 (diff) | |
download | gtk+-23b6699ec35d069c3f4a7b3a90bb5881740aab8e.tar.gz |
Container: Don’t scroll to unset focus child coord
In gtk_container_real_set_focus_child(), we try to scroll to the
position of the new :focus-child if we have h or v adjustments.
gtk_widget_translate_coordinates() returns FALSE if neither widget is
realized or in other situations that cause output parameters x and y not
to be set. Thus, if the caller did not initialise x/y and uses them even
if the function returned FALSE, they are using uninitialised variables.
In gtk_container_real_set_focus_child(), we did not check the return
value but merrily went ahead and used x and y regardless. This is UB, as
revealed by Valgrind, as well as being pointless.
The trivial fix is to exit early if (!gtk_widget_translate_coordinates).
https://bugzilla.gnome.org/show_bug.cgi?id=776909
Diffstat (limited to 'gtk/gtkcontainer.c')
-rw-r--r-- | gtk/gtkcontainer.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c index bc52c99554..b24bef843d 100644 --- a/gtk/gtkcontainer.c +++ b/gtk/gtkcontainer.c @@ -2038,8 +2038,7 @@ gtk_container_real_set_focus_child (GtkContainer *container, g_return_if_fail (GTK_IS_CONTAINER (container)); g_return_if_fail (focus_child == NULL || GTK_IS_WIDGET (focus_child)); - /* check for h/v adjustments - */ + /* Check for h/v adjustments and scroll to show the focus child if possible */ if (focus_child) { GtkAdjustment *hadj; @@ -2056,8 +2055,9 @@ gtk_container_real_set_focus_child (GtkContainer *container, while (gtk_widget_get_focus_child (child)) child = gtk_widget_get_focus_child (child); - gtk_widget_translate_coordinates (child, focus_child, - 0, 0, &x, &y); + if (!gtk_widget_translate_coordinates (child, focus_child, + 0, 0, &x, &y)) + return; _gtk_widget_get_allocation (focus_child, &allocation); x += allocation.x; |