Popover: Clarify/guard out rect of get_pointing_to
authorDaniel Boles <dboles.src@gmail.com>
Sun, 11 Jun 2023 10:37:45 +0000 (11:37 +0100)
committerRaspbian forward porter <root@raspbian.org>
Wed, 22 Nov 2023 04:54:09 +0000 (04:54 +0000)
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.

Bug: https://gitlab.gnome.org/GNOME/gtk/-/issues/893#note_1766079
Origin: 3.24.39, commit:a6d40b610be6acb635d8732c11bb6d866bf2e95d

Gbp-Pq: Name Popover-Clarify-guard-out-rect-of-get_pointing_to.patch

gtk/gtkpopover.c

index 82ad2fc29183251626d3442f2311a6d30a92317e..b812e0e5688c4d46cec1b4f20f6ec4b8efba868f 100644 (file)
 #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;
 }