[PATCH:libFS 2/2] Mark pattern argument to FSListFonts* as const char *

Alan Coopersmith alan.coopersmith at oracle.com
Sun Nov 13 09:53:28 PST 2011


On 11/12/11 02:15, Mark Kettenis wrote:
>> From: Alan Coopersmith<alan.coopersmith at oracle.com>
>> Date: Fri, 11 Nov 2011 21:43:05 -0800
>>
>> Needed to fix gcc -Wwrite-strings warnings in clients such as fslsfonts
>>
>> diff --git a/src/FSlibInt.c b/src/FSlibInt.c
>> index 5a33b64..eea9840 100644
>> --- a/src/FSlibInt.c
>> +++ b/src/FSlibInt.c
>> @@ -536,7 +536,7 @@ _FSReadPad(
>>   void
>>   _FSSend(
>>       register FSServer	*svr,
>> -    char		*data,
>> +    const char		*data,
>>       register long	 size)
>>   {
>>       struct iovec iov[3];
>> @@ -591,7 +591,7 @@ _FSSend(
>>   	    }
>>
>>   	InsertIOV(svr->buffer, svrbufsize)
>> -	InsertIOV(data, size)
>> +	InsertIOV((char *)data, size)
>
> Are you sure InsertIOV() can't modify the data you pass it?  If so,
> you should constify it and drop the cast.

I can't constify it - it's a macro to fill in struct iovec contents,
which does:
                 iov[i].iov_base = (pointer) + before; \

struct iovec is defined in the POSIX API, and can't be changed - in
this case we're filling in pointers for writev() to read from and
write to the socket, so it should not modify them, but the same
struct is used for readv() to fill in the buffers so the struct
can't be constified without redefining the API to use different
ones for read and write.   (writev does specify its argument as
const struct iovec *iov, which seems as close to a guarantee as
we'll get with the current API.)

Again, this mirrors what was done for the code in libX11 that this
code was originally copied from.

-- 
	-Alan Coopersmith-        alan.coopersmith at oracle.com
	 Oracle Solaris Platform Engineering: X Window System



More information about the xorg-devel mailing list