[retro-gtk] gl-display: Check divisions by 0
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [retro-gtk] gl-display: Check divisions by 0
- Date: Wed, 28 Jul 2021 12:42:40 +0000 (UTC)
commit 4289387b7961b4e07a5ae0e40026c294b00d2461
Author: Adrien Plazas <kekun plazas laposte net>
Date: Wed Jul 28 14:23:33 2021 +0200
gl-display: Check divisions by 0
This ensures we use strictly positive values when checking if
coordinates are part of the display, avoiding odd results and divisions
by 0.
retro-gtk/retro-gl-display.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/retro-gtk/retro-gl-display.c b/retro-gtk/retro-gl-display.c
index dff5c71..debc2e3 100644
--- a/retro-gtk/retro-gl-display.c
+++ b/retro-gtk/retro-gl-display.c
@@ -85,7 +85,7 @@ set_pixdata (RetroGLDisplay *self,
gtk_widget_queue_draw (GTK_WIDGET (self));
}
-static void
+static gboolean
get_video_box (RetroGLDisplay *self,
gdouble *width,
gdouble *height,
@@ -108,6 +108,9 @@ get_video_box (RetroGLDisplay *self,
w = (gdouble) gtk_widget_get_allocated_width (GTK_WIDGET (self)) * scale;
h = (gdouble) gtk_widget_get_allocated_height (GTK_WIDGET (self)) * scale;
+ if (self->aspect_ratio <= 0 || w <= 0 || h <= 0)
+ return FALSE;
+
// Set the size of the display.
display_ratio = (gdouble) self->aspect_ratio;
allocated_ratio = w / h;
@@ -125,6 +128,8 @@ get_video_box (RetroGLDisplay *self,
// Set the position of the display.
*x = (w - *width) / 2;
*y = (h - *height) / 2;
+
+ return TRUE;
}
static gboolean
@@ -502,7 +507,8 @@ retro_gl_display_get_coordinates_on_display (RetroGLDisplay *self,
g_return_val_if_fail (display_x != NULL, FALSE);
g_return_val_if_fail (display_y != NULL, FALSE);
- get_video_box (self, &w, &h, &x, &y);
+ if (!get_video_box (self, &w, &h, &x, &y))
+ return FALSE;
scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (self));
widget_x *= scale_factor;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]