Current-Users archive

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

Re: Casting ctype lookups

On Wed, 14 Nov 2012, D'Arcy J.M. Cain wrote:
Would this be safer?

#define toupper(c)\
 ((int)((_toupper_tab_ + 1)[(int)(unsigned char)(c)]))

No.  That would break when the caller passes the int value EOF.

I believe that there's nothing wrong with NetBSD's definitions of these functions and macros. If the caller gets a warning about them, then there's a problem in the caller's code.

The only improvement that I can think of would be to abort with a descriptive message if the value is out of range, but to do so in a way that does not hurt performance for non-buggy callers.

--apb (Alan Barrett)

Home | Main Index | Thread Index | Old Index