tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Suggested change of ctype.h



On Sat, Jun 13, 2009 at 06:50:23PM +0200, Juergen Buchmueller wrote:
> Hello,
> several times I stumbled over gcc's warnings regarding the use of a
> signed character as index in the ctype.h functions.....

Yes... I think that is why that waring exists!

> Other OSes return the original value for {toupper|tolower}(char<0) and
> to me it seems to make sense to clean up this little annoyance.

If they do, they are broken!

> I changed /usr/include/ctype.h to the following:

> static __inline int islower(int c) {
>         return (c < 0) ? 0 : (int)((_ctype_ + 1)[c] & _L);

The above is broken, 'char' values between -128 and -1 can be lower case.
More particularly the domain of all the ctype functions is clearly
stated in all the documentation as EOF plus the values of 'unsigned char',
the behaviour (not the result) for other values is 'undefined'.

Typically EOF is -1 and 0xff may be a valid character, the functions need
to correctly discriminate between the two.

        David

-- 
David Laight: david%l8s.co.uk@localhost


Home | Main Index | Thread Index | Old Index