On Fri, 23 Nov 2012, Alexander Hall wrote: > On 11/23/12 02:17, Philip Guenther wrote: ... > > The argument to tolower() must be a value in the range [EOF, > > 0..UCHAR_MAX]. When taking characters from a char * string, you need > > to cast the value to (unsigned char), ala > > tolower((unsigned char)*src) > > Ok... Is this documented somewhere or just common knowledge?
It's a property of all the <ctype.h> functions, which we've documented for the is* functions in the CAVEATS section of their pages; here's the diff to add the matching statement to tolower(3) and toupper(3). Philip Index: gen/tolower.3 =================================================================== RCS file: /cvs/src/lib/libc/gen/tolower.3,v retrieving revision 1.11 diff -u -p -r1.11 tolower.3 --- gen/tolower.3 31 May 2007 19:19:29 -0000 1.11 +++ gen/tolower.3 23 Nov 2012 22:12:21 -0000 @@ -99,3 +99,11 @@ and .Fn _tolower functions conform to .St -ansiC . +.Sh CAVEATS +The argument to +.Nm +must be +.Dv EOF +or representable as an +.Li unsigned char ; +otherwise, the result is undefined. Index: gen/toupper.3 =================================================================== RCS file: /cvs/src/lib/libc/gen/toupper.3,v retrieving revision 1.13 diff -u -p -r1.13 toupper.3 --- gen/toupper.3 31 May 2007 19:19:29 -0000 1.13 +++ gen/toupper.3 23 Nov 2012 22:12:21 -0000 @@ -97,3 +97,11 @@ The .Fn toupper function conforms to .St -ansiC . +.Sh CAVEATS +The argument to +.Nm +must be +.Dv EOF +or representable as an +.Li unsigned char ; +otherwise, the result is undefined.