Bug 793951 - Fix crashes when some external APIs fail

Check the return values of some functions and set errors or print
a message to stderr if they fail.
This commit is contained in:
Zhouyang 2018-03-26 21:25:10 +02:00 committed by Michael Natterer
parent fae9c28354
commit a6fd24a953
3 changed files with 24 additions and 4 deletions

View File

@ -75,9 +75,10 @@ gimp_display_shell_layer_select_init (GimpDisplayShell *shell,
gint move,
guint32 time)
{
LayerSelect *layer_select;
GimpImage *image;
GimpLayer *layer;
LayerSelect *layer_select;
GimpImage *image;
GimpLayer *layer;
GdkGrabStatus status;
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
@ -97,7 +98,9 @@ gimp_display_shell_layer_select_init (GimpDisplayShell *shell,
gtk_widget_show (layer_select->window);
gdk_keyboard_grab (gtk_widget_get_window (layer_select->window), FALSE, time);
status = gdk_keyboard_grab (gtk_widget_get_window (layer_select->window), FALSE, time);
if (status != GDK_GRAB_SUCCESS)
g_printerr ("gdk_keyboard_grab failed with status %d\n", status);
}

View File

@ -888,6 +888,13 @@ load_image (const gchar *filename,
}
info = png_create_info_struct (pp);
if (! info)
{
g_set_error (error, 0, 0,
_("Error while reading '%s'. Could not create PNG header info structure."),
gimp_filename_to_utf8 (filename));
return -1;
}
if (setjmp (png_jmpbuf (pp)))
{
@ -1537,6 +1544,13 @@ save_image (const gchar *filename,
}
info = png_create_info_struct (pp);
if (! info)
{
g_set_error (error, 0, 0,
_("Error while exporting '%s'. Could not create PNG header info structure."),
gimp_filename_to_utf8 (filename));
return FALSE;
}
if (setjmp (png_jmpbuf (pp)))
{

View File

@ -408,6 +408,9 @@ parse_colors (XpmImage *xpm_image)
#ifndef XPM_NO_X
/* open the display and get the default color map */
display = XOpenDisplay (NULL);
if (display == NULL)
g_printerr ("Could not open display\n");
colormap = DefaultColormap (display, DefaultScreen (display));
#endif