string.c:strncasecmp() calls __tolower
from include/linux/ctype.h which expects an unsinged char
.
EDITed to add: In general you always want to pass unsigned char
to ctype.h functions because of C Standard ยง7.4, which says the behavior is undefined if the argument to ctype.h functions is not representable as unsigned char
or EOF
. So that probably explains the "Yes, Virginia" bit.
What is a bit more mysterious is that include/linux/ctype.h actually appears idiot-proof in this respect, because it does its own safety-minded cast in #define __ismask(x) (_ctype[(int)(unsigned char)(x)])
. I'm not sure when the "Yes, Virginia" comment was added relative to this other line, but with the current version of include/linux/ctype.h
it appears that string.c:strncasecmp()
would work fine even with char
for c1
and c2
. I haven't really tried to change & test it that way though...
Also if you go back to Linux 2.0.40's ctype.h, the safety-minded cast ((int)(unsigned char)
) is not there anymore. There's no "Virginia" comment either in 2.0.40's string.c, but there's not even a strncasecmp
in it. It looks like both changes were made somewhere in between Linux 2.0 and 2.2, but I can't tell you more right now which came first, etc.