[PATCH lib/libX11] Don't use caddr_t casts

Jon TURNEY jon.turney at dronecode.org.uk
Sun Feb 19 06:31:54 PST 2012


On 18/02/2012 19:11, Jamey Sharp wrote:
> On Sat, Feb 18, 2012 at 05:21:24PM +0000, Jon TURNEY wrote:
>> Casting a (const char *) to (caddr_t) to assign to iovec.io_base
>> seems pointless. caddr_t isn't used anywhere else in xcb or libX11
> 
> According to the libxcb git history, I replaced (caddr_t) with (char *)
> in 2006 to "help DragonFly and Solaris". I'd be fine with this patch if
> it explicitly cast to (char *), which I believe suppresses the constness
> warning.

Updated patch attached.

But you still get a warning that you are discarding constness, because you are :-)

Using an explicit (char *) cast just changes the warning from:

/opt/wip/jhbuild/git/xorg/lib/libX11/src/xcb_io.c: In function '_XSend':
/opt/wip/jhbuild/git/xorg/lib/libX11/src/xcb_io.c:481:18: warning: assignment
discards qualifiers from pointer target type
/opt/wip/jhbuild/git/xorg/lib/libX11/src/xcb_io.c:483:18: warning: assignment
discards qualifiers from pointer target type

to:

/opt/wip/jhbuild/git/xorg/lib/libX11/src/xcb_io.c: In function '_XSend':
/opt/wip/jhbuild/git/xorg/lib/libX11/src/xcb_io.c:481:2: warning: cast
discards qualifiers from pointer target type [-Wcast-qual]
/opt/wip/jhbuild/git/xorg/lib/libX11/src/xcb_io.c:483:2: warning: cast
discards qualifiers from pointer target type [-Wcast-qual]

>> Note: there's a warning about dropping constness here, but that's
>> going to be unfixable as long as xcb_writev() takes a non-const struct
>> iovec as a parameter.
> 
> C's rules regarding const always confuse me, but I'm pretty sure even
> that wouldn't help. If the struct iovec is declared const, that just
> means XCB won't change where the iov_base pointers point. It doesn't
> mean XCB promises to refrain from writing through those pointers.

You are correct, I mis-stated the issue here. You are always going to get a
warning here because struct iovec can't represent the constness correctly.

I'm guessing xcb functions don't modify the iovec itself, so it could be
const, but that's a separate issue.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: 0001-Don-t-use-caddr_t-casts.patch
URL: <http://lists.x.org/archives/xorg-devel/attachments/20120219/23484109/attachment.asc>


More information about the xorg-devel mailing list