[PATCH] exa: don't need to check for NULL pointer if we already assumed it has a value

Dan Nicholson dbn.lists at gmail.com
Sat Apr 17 08:45:38 PDT 2010


On Fri, Apr 16, 2010 at 8:42 AM, Tiago Vignatti
<tiago.vignatti at nokia.com> wrote:
> the alternative would be to check ps in the beginning of the function.
>
> Signed-off-by: Tiago Vignatti <tiago.vignatti at nokia.com>
> ---
>  exa/exa.c |    2 --
>  1 files changed, 0 insertions(+), 2 deletions(-)
>
> diff --git a/exa/exa.c b/exa/exa.c
> index 590d9a5..51697bc 100644
> --- a/exa/exa.c
> +++ b/exa/exa.c
> @@ -779,14 +779,12 @@ exaCloseScreen(int i, ScreenPtr pScreen)
>     unwrap(pExaScr, pScreen, BitmapToRegion);
>     unwrap(pExaScr, pScreen, CreateScreenResources);
>  #ifdef RENDER
> -    if (ps) {
>        unwrap(pExaScr, ps, Composite);
>        if (pExaScr->SavedGlyphs)
>            unwrap(pExaScr, ps, Glyphs);
>        unwrap(pExaScr, ps, Trapezoids);
>        unwrap(pExaScr, ps, Triangles);
>        unwrap(pExaScr, ps, AddTraps);
> -    }
>  #endif
>
>     xfree (pExaScr);
> --
> 1.6.0.4

It seems it would be better to check ps unless you're pretty sure
pScreen always has a PictureScreen.

Looking at this code showed me another "bug".

#ifdef RENDER
    PictureScreenPtr    ps = GetPictureScreenIfSet(pScreen);
#endif

    if (ps->Glyphs == exaGlyphs)
        exaGlyphsFini(pScreen);

Shouldn't this whole block be under RENDER like the later accesses to
ps? Incidentally, if you just change the conditional to "if (ps &&
ps->Glyphs == exaGlyphs)", then the NULL pointer won't be dereferenced
either.

--
Dan


More information about the xorg-devel mailing list