[cairo] [PATCH 1/2] Don't return NULL to clients when getting image
Bryce Harrington
bryce at osg.samsung.com
Tue Sep 23 02:48:08 PDT 2014
On Tue, Sep 23, 2014 at 10:07:30AM +0100, Chris Wilson wrote:
> On Tue, Sep 23, 2014 at 01:27:35AM -0700, Bryce Harrington wrote:
> > On Tue, Sep 23, 2014 at 07:26:51AM +0100, Chris Wilson wrote:
> > > On Mon, Sep 22, 2014 at 03:50:25PM -0700, Bryce Harrington wrote:
> > > > diff --git a/src/win32/cairo-win32-surface.c b/src/win32/cairo-win32-surface.c
> > > > index 7cd46fc..f11cbd8 100644
> > > > --- a/src/win32/cairo-win32-surface.c
> > > > +++ b/src/win32/cairo-win32-surface.c
> > > > @@ -188,7 +188,7 @@ cairo_surface_t *
> > > > cairo_win32_surface_get_image (cairo_surface_t *surface)
> > > > {
> > > > if (surface->backend->type != CAIRO_SURFACE_TYPE_WIN32)
> > >
> > > This is still dangerous - error surfaces have no surface->backend to
> > > dereference.
> > > -Chris
> >
> > Good point. Obviously users should not be trying to use error surfaces,
> > but I suppose they might not check.
> >
> > What would you suggest? An assert or NULL check on surface->backend?
> > Or introduce error backends?
>
> We use surface->backend == NULL as an indicator that it is an error
> surface. See _cairo_surface_is_image() et al.
Okay, that makes sense. So null checks, possibly via inlined helper
functions ala _cairo_surface_is_image, would be the solution here.
Looks like there's quite a few places where surface->backend gets
referenced, that could possibly use such a check.
Ravi - this looks like this refactoring might be up your alley if you're
interested.
Bryce
More information about the cairo
mailing list