Re: Problem with gdk_image_get() failing
- From: Ramiro Estrugo <ramiro eazel com>
- To: gtk-devel-list gnome org
- Subject: Re: Problem with gdk_image_get() failing
- Date: Tue, 19 Dec 2000 18:01:06 -0800
Anyone care to comment on this fix ?
I'd be happy to make patches for both gtk 1.2 and 1.3. Also the
indentation style in the patch is wrong wrt to that in gtk, i can fix
that.
??
thanks
-re
Ramiro Estrugo wrote:
>
> I just ran into a problem with gdk_image_get(). The issue is that if
> XGetImage() fails and returns NULL, gdk_image_get () will segfault
> trying to dereference the NULL ximage result.
>
> For example, if the dimensions passed to XGetImage() are bogus, a
> BadMatch x error is triggered and the application seg faults.
>
> Now, of course I agree that the caller of XGetImage() should pass in
> good values and that's what my code does. Im sure that the passed in
> values are valid...
>
> Im using gdk_pixbuf_get_from_drawable(). It does some sanity checks on
> the passed in dimensions using gdk_window_get_size(). Unfortunately the
> cached values returned by gdk_window_get_size() are out of whack with
> reality thus producing the BadMatch x error.
>
> I have a test program that I can post that shows the problem, but it
> seems harmless to make gdk_image_get() more robust - especially since
> the caller will still get an x protocol error.
>
> The simple attatched patch does this by calling XGetImage() before
> allocating the private image struct and returning NULL if XGetImage()
> fails.
>
> thanks
>
> -re
>
> ------------------------------------------------------------------------
> Index: gdkimage.c
> ===================================================================
> RCS file: /cvs/gnome/gtk+/gdk/gdkimage.c,v
> retrieving revision 1.14.2.4
> diff -u -u -r1.14.2.4 gdkimage.c
> --- gdkimage.c 2000/11/18 16:59:39 1.14.2.4
> +++ gdkimage.c 2000/12/15 03:48:17
> @@ -342,6 +342,7 @@
> GdkImage *image;
> GdkImagePrivate *private;
> GdkWindowPrivate *win_private;
> + XImage *ximage;
>
> g_return_val_if_fail (window != NULL, NULL);
>
> @@ -349,16 +350,20 @@
> if (win_private->destroyed)
> return NULL;
>
> + ximage = XGetImage (gdk_display,
> + win_private->xwindow,
> + x, y, width, height,
> + AllPlanes, ZPixmap);
> +
> + if (ximage == NULL)
> + return NULL;
> +
> private = g_new (GdkImagePrivate, 1);
> image = (GdkImage*) private;
>
> private->xdisplay = gdk_display;
> private->image_put = gdk_image_put_normal;
> - private->ximage = XGetImage (private->xdisplay,
> - win_private->xwindow,
> - x, y, width, height,
> - AllPlanes, ZPixmap);
> -
> + private->ximage = ximage;
> image->type = GDK_IMAGE_NORMAL;
> image->visual = gdk_window_get_visual (window);
> image->width = width;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]