compiler warnings

Martin Pool mbp at samba.org
Tue Apr 9 00:40:05 EST 2002


On 27 Mar 2002, "Nelson H. F. Beebe" <beebe at math.utah.edu> wrote:
> There are quite a few compilation warnings from rsync-2.5.5rc1 that
> could be eliminated by code cleanup.

Thanks for reporting these.

At this stage I'm not going to patch warnings in popt or zlib because
we ought to keep in sync with the upstream versions.  

> gcc on the DEC Alpha OSF/1 caught several instances of char
> subscripts; these are potentially erroneous because char is a signed
> type on many architectures, but naive programmers erroneously expect
> that
> 
> 	int arr[256];
> 	char c;
> 	c = 255;
> 	arr[c] = 123;

That's a very good point.  It looks like GNU libc will always be
tolerant of values in [-127, 255] passed to these functions, but
that's not true for all libraries, and it's really not good practice
anyhow.

I suppose the thing to do is not to just cast to (int) as the warning
might suggest, but rather to make sure always to interpret the bytes
as unsigned chars when they're being used as text.

-- 
Martin 




More information about the rsync mailing list