Popover: Clarify/guard out rect of get_pointing_to

Clarify that we zero out the widget coords and only keep its dimensions.

If we have no widget to fall-back to, memset to 0 the output @rect since
we return FALSE whether or not we have widget, so protect users from not
knowing if there was a widget and possibly accessing uninitialised ints.

Fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/893#note_1766079
This commit is contained in:
Daniel Boles 2023-06-11 11:37:45 +01:00
parent ad07e9043f
commit a6d40b610b

View File

@ -112,6 +112,7 @@
#include "gtkstylecontextprivate.h"
#include "gtkprogresstrackerprivate.h"
#include "gtksettingsprivate.h"
#include <string.h> /* memset */
#ifdef GDK_WINDOWING_WAYLAND
#include "wayland/gdkwayland.h"
@ -2316,7 +2317,7 @@ gtk_popover_set_pointing_to (GtkPopover *popover,
* If a rectangle to point to has been set, this function will
* return %TRUE and fill in @rect with such rectangle, otherwise
* it will return %FALSE and fill in @rect with the attached
* widget coordinates.
* widget width and height if a widget exists, otherwise it will zero-out @rect.
*
* Returns: %TRUE if a rectangle to point to was set.
**/
@ -2336,6 +2337,8 @@ gtk_popover_get_pointing_to (GtkPopover *popover,
gtk_widget_get_allocation (priv->widget, rect);
rect->x = rect->y = 0;
}
else
memset (rect, 0, sizeof (GdkRectangle));
return priv->has_pointing_to;
}