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

walter harms wharms at bfs.de
Sat Jun 30 09:27:28 PDT 2012



Am 30.06.2012 17:04, schrieb Alan Coopersmith:
> On 06/30/12 02:38 AM, walter harms wrote:
>>> -    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;
> 
> Nope - Xlib doesn't do the same things there, since in Xlib, a GC
> is a pointer to a struct, while a Pixmap is simply an XID (integer).
> 
> XCreateGC can return NULL if malloc fails:
>   http://cgit.freedesktop.org/xorg/lib/libX11/tree/src/CrGC.c#n64
> 
> XCreatePixamp doesn't malloc, simply returns the next available XID:
>   http://cgit.freedesktop.org/xorg/lib/libX11/tree/src/CrPixmap.c#n40
> 
yep,
 XAllocID(dpy) is the core but can it never fail ?
 according to the man page:
 "XCreatePixmap can generate BadAlloc, BadDrawable, and BadValue errors."

to be clear if you say "this can never happen" it is ok with me but i am wondering ...

re,
 wh


More information about the xorg-devel mailing list