Put the code to protect against broken loaders that forget to set error in

2006-07-16  Matthias Clasen  <mclasen@redhat.com>

	* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module)
	(gdk_pixbuf_loader_write, gdk_pixbuf_loader_close)
	(gdk_pixbuf_loader_ensure_error): Put the code to protect
	against broken loaders that forget to set error in an
	auxiliary function and call it in more places.  (#346428,
	 Catmur)
This commit is contained in:
Matthias Clasen
2006-07-17 02:37:29 +00:00
committed by Matthias Clasen
parent b8b28b6782
commit c48afeca8a
2 changed files with 39 additions and 32 deletions

View File

@ -1,5 +1,12 @@
2006-07-16 Matthias Clasen <mclasen@redhat.com> 2006-07-16 Matthias Clasen <mclasen@redhat.com>
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module)
(gdk_pixbuf_loader_write, gdk_pixbuf_loader_close)
(gdk_pixbuf_loader_ensure_error): Put the code to protect
against broken loaders that forget to set error in an
auxiliary function and call it in more places. (#346428,
Catmur)
* io-xbm.c: Fix incremental loading of * io-xbm.c: Fix incremental loading of
xbms. (#346427, Ed Catmur) xbms. (#346427, Ed Catmur)
Also make the xbm loader accept const variations. Also make the xbm loader accept const variations.

View File

@ -303,6 +303,27 @@ gdk_pixbuf_loader_update (GdkPixbuf *pixbuf,
MIN (height, gdk_pixbuf_animation_get_height (priv->animation))); MIN (height, gdk_pixbuf_animation_get_height (priv->animation)));
} }
/* Defense against broken loaders; DO NOT take this as a GError example! */
static void
gdk_pixbuf_loader_ensure_error (GdkPixbufLoader *loader,
GError **error)
{
GdkPixbufLoaderPrivate *priv = loader->priv;
if (error == NULL || *error != NULL)
return;
g_warning ("Bug! loader '%s' didn't set an error on failure",
priv->image_module->module_name);
g_set_error (error,
GDK_PIXBUF_ERROR,
GDK_PIXBUF_ERROR_FAILED,
_("Internal error: Image loader module '%s' failed to"
" complete an operation, but didn't give a reason for"
" the failure"),
priv->image_module->module_name);
}
static gint static gint
gdk_pixbuf_loader_load_module (GdkPixbufLoader *loader, gdk_pixbuf_loader_load_module (GdkPixbufLoader *loader,
const char *image_type, const char *image_type,
@ -358,23 +379,7 @@ gdk_pixbuf_loader_load_module (GdkPixbufLoader *loader,
if (priv->context == NULL) if (priv->context == NULL)
{ {
/* Defense against broken loaders; DO NOT take this as a GError gdk_pixbuf_loader_ensure_error (loader, error);
* example
*/
if (error && *error == NULL)
{
g_warning ("Bug! loader '%s' didn't set an error on failure",
priv->image_module->module_name);
g_set_error (error,
GDK_PIXBUF_ERROR,
GDK_PIXBUF_ERROR_FAILED,
_("Internal error: Image loader module '%s'"
" failed to begin loading an image, but didn't"
" give a reason for the failure"),
priv->image_module->module_name);
}
return 0; return 0;
} }
@ -450,7 +455,10 @@ gdk_pixbuf_loader_write (GdkPixbufLoader *loader,
eaten = gdk_pixbuf_loader_eat_header_write (loader, buf, count, error); eaten = gdk_pixbuf_loader_eat_header_write (loader, buf, count, error);
if (eaten <= 0) if (eaten <= 0)
{
gdk_pixbuf_loader_ensure_error (loader, error);
return FALSE; return FALSE;
}
count -= eaten; count -= eaten;
buf += eaten; buf += eaten;
@ -461,19 +469,8 @@ gdk_pixbuf_loader_write (GdkPixbufLoader *loader,
gboolean retval; gboolean retval;
retval = priv->image_module->load_increment (priv->context, buf, count, retval = priv->image_module->load_increment (priv->context, buf, count,
error); error);
if (!retval && error && *error == NULL) if (!retval)
{ gdk_pixbuf_loader_ensure_error (loader, error);
/* Fix up busted image loader */
g_warning ("Bug! loader '%s' didn't set an error on failure",
priv->image_module->module_name);
g_set_error (error,
GDK_PIXBUF_ERROR,
GDK_PIXBUF_ERROR_FAILED,
_("Internal error: Image loader module '%s'"
" failed to begin loading an image, but didn't"
" give a reason for the failure"),
priv->image_module->module_name);
}
return retval; return retval;
} }
@ -716,8 +713,11 @@ gdk_pixbuf_loader_close (GdkPixbufLoader *loader,
if (priv->image_module && priv->image_module->stop_load && priv->context) if (priv->image_module && priv->image_module->stop_load && priv->context)
{ {
if (!priv->image_module->stop_load (priv->context, error)) if (!priv->image_module->stop_load (priv->context, error))
{
gdk_pixbuf_loader_ensure_error (loader, error);
retval = FALSE; retval = FALSE;
} }
}
priv->closed = TRUE; priv->closed = TRUE;
if (priv->image_module && priv->holds_threadlock) { if (priv->image_module && priv->holds_threadlock) {