[PATCH:libX11 2/2] Convert XCreate{Pix, Bit}map...Data to use C99 designated initializers

walter harms wharms at bfs.de
Sat Jun 30 02:38:32 PDT 2012



Am 30.06.2012 08:11, schrieb Alan Coopersmith:
> Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
> ---
>  src/CrBFData.c  |   42 ++++++++++++++++++++----------------------
>  src/CrPFBData.c |   50 +++++++++++++++++++++++++-------------------------
>  2 files changed, 45 insertions(+), 47 deletions(-)
> 
> diff --git a/src/CrBFData.c b/src/CrBFData.c
> index 9515875..6708a9b 100644
> --- a/src/CrBFData.c
> +++ b/src/CrBFData.c
> @@ -53,30 +53,28 @@ Pixmap XCreateBitmapFromData(
>       unsigned int width,
>       unsigned int height)
>  {
> -    XImage ximage;
> -    GC gc;
> -    Pixmap pix;
> -
> -    pix = XCreatePixmap(display, d, width, height, 1);
> -    gc = XCreateGC(display, pix, (unsigned long) 0, (XGCValues *) 0);
> +    Pixmap pix = XCreatePixmap(display, d, width, height, 1);

if you assume that gc can fail you should check pix also
	if ( pix == NULL )
	    return (Pixmap) None;


> +    GC gc = XCreateGC(display, pix, (unsigned long) 0, (XGCValues *) 0);
>      if (gc == NULL) {
>          XFreePixmap(display, pix);
>          return (Pixmap) None;
> +    } else {
> +        XImage ximage = {
> +            .height = height,
> +            .width = width,
> +            .depth = 1,
> +            .bits_per_pixel = 1,
> +            .xoffset = 0,
> +            .format = XYPixmap,
> +            .data = (char *) data,
> +            .byte_order = LSBFirst,
> +            .bitmap_unit = 8,
> +            .bitmap_bit_order = LSBFirst,
> +            .bitmap_pad = 8,
> +            .bytes_per_line = (width + 7) / 8,
> +        };
> +        XPutImage(display, pix, gc, &ximage, 0, 0, 0, 0, width, height);
> +        XFreeGC(display, gc);
> +        return(pix);
>      }
> -    ximage.height = height;
> -    ximage.width = width;
> -    ximage.depth = 1;
> -    ximage.bits_per_pixel = 1;
> -    ximage.xoffset = 0;
> -    ximage.format = XYPixmap;
> -    ximage.data = (char *)data;
> -    ximage.byte_order = LSBFirst;
> -    ximage.bitmap_unit = 8;
> -    ximage.bitmap_bit_order = LSBFirst;
> -    ximage.bitmap_pad = 8;
> -    ximage.bytes_per_line = (width+7)/8;
> -
> -    XPutImage(display, pix, gc, &ximage, 0, 0, 0, 0, width, height);
> -    XFreeGC(display, gc);
> -    return(pix);
>  }
> diff --git a/src/CrPFBData.c b/src/CrPFBData.c
> index d343420..ef48219 100644
> --- a/src/CrPFBData.c
> +++ b/src/CrPFBData.c
> @@ -58,33 +58,33 @@ Pixmap XCreatePixmapFromBitmapData(
>      unsigned long bg,
>      unsigned int depth)
>  {
> -    XImage ximage;
> -    GC gc;
> -    XGCValues gcv;
> -    Pixmap pix;
> -
> -    pix = XCreatePixmap(display, d, width, height, depth);
> -    gcv.foreground = fg;
> -    gcv.background = bg;
> -    gc = XCreateGC(display, pix, GCForeground|GCBackground, &gcv);
> +    Pixmap pix = XCreatePixmap(display, d, width, height, depth);

	if ( pix == NULL )
	    return (Pixmap) None;

just my 2 cents,
re,
 wh

> +    XGCValues gcv = {
> +        .foreground = fg,
> +        .background = bg
> +    };
> +    GC gc = XCreateGC(display, pix, GCForeground|GCBackground, &gcv);
>      if (gc == NULL) {
>          XFreePixmap(display, pix);
>          return (Pixmap) None;
> -    }
> -    ximage.height = height;
> -    ximage.width = width;
> -    ximage.depth = 1;
> -    ximage.bits_per_pixel = 1;
> -    ximage.xoffset = 0;
> -    ximage.format = XYBitmap;
> -    ximage.data = data;
> -    ximage.byte_order = LSBFirst;
> -    ximage.bitmap_unit = 8;
> -    ximage.bitmap_bit_order = LSBFirst;
> -    ximage.bitmap_pad = 8;
> -    ximage.bytes_per_line = (width+7)/8;
> +    } else {
> +        XImage ximage = {
> +            .height = height,
> +            .width = width,
> +            .depth = 1,
> +            .bits_per_pixel = 1,
> +            .xoffset = 0,
> +            .format = XYBitmap,
> +            .data = data,
> +            .byte_order = LSBFirst,
> +            .bitmap_unit = 8,
> +            .bitmap_bit_order = LSBFirst,
> +            .bitmap_pad = 8,
> +            .bytes_per_line = (width + 7) / 8
> +        };
>  
> -    XPutImage(display, pix, gc, &ximage, 0, 0, 0, 0, width, height);
> -    XFreeGC(display, gc);
> -    return(pix);
> +        XPutImage(display, pix, gc, &ximage, 0, 0, 0, 0, width, height);
> +        XFreeGC(display, gc);
> +        return(pix);
> +    }
>  }


More information about the xorg-devel mailing list