[gimp] app: fix a "Floating point exception" crash.



commit 636b77f7d341af74e9d0b19478644c74664a9e69
Author: Jehan <jehan girinstud io>
Date:   Wed Feb 13 20:49:49 2019 +0100

    app: fix a "Floating point exception" crash.
    
    `icon_space_width` is set when GtkWidget::style-updated signal is
    emitted. In some cases, it was possible that gimp_statusbar_set_text()
    is run before this happens, in which case, a division by zero would
    crash the software.
    
    I encountered this case in some rare occasions when duplicating an image
    with ctrl-d, then as Ctrl was hold, the message "Click in any image to
    pick the foreground color" was pushed on the brand new statusbar as it
    is created (hence a race condition occurs with the signal handler and
    this message). This was therefore not reproducible every time, but easy
    enough to reproduce with multiple tests.

 app/display/gimpstatusbar.c | 7 +++++++
 1 file changed, 7 insertions(+)
---
diff --git a/app/display/gimpstatusbar.c b/app/display/gimpstatusbar.c
index c5f434bd4c..c301a12d21 100644
--- a/app/display/gimpstatusbar.c
+++ b/app/display/gimpstatusbar.c
@@ -685,6 +685,13 @@ gimp_statusbar_set_text (GimpStatusbar *statusbar,
 
           scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (statusbar));
 
+          /* Make sure icon_space_width has been initialized to avoid a
+           * division by zero.
+           */
+          if (statusbar->icon_space_width == 0)
+            gimp_statusbar_style_updated (GTK_WIDGET (statusbar));
+          g_return_if_fail (statusbar->icon_space_width != 0);
+
           /* prepend enough spaces for the icon plus one space */
           n_spaces = (gdk_pixbuf_get_width (statusbar->icon) / scale_factor +
                       ICON_SPACING) / statusbar->icon_space_width;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]