|
Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com |
Re: [Patch:] restore the native use of isdigit() instead of ap_isdigit() in httpd.
From: Garance A Drosihn (drosih
rpi.edu)
Date: Thu Mar 30 2006 - 16:54:56 CST
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
At 9:50 PM +0200 3/30/06, joerg
britannica.bec.de wrote:
>On Thu, Mar 30, 2006 at 02:44:19PM -0500, Daniel Ouellet wrote:
>> What I did is to check how it was process by the macro in the
>> /include/ctype.h:
>>
>> __CTYPE_INLINE int isdigit(int c)
>> {
>> return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _N));
>> }
>
>The important point is that isdigit should not be called with
>an argment of type char. As I said, it works on OpenBSD. It
>does not work on other systems. isdigit is a documented
>interface, so it should be used correctly, since someone might
>want to use it on a different system later.
Fwiw, what I do is define is*ch and to*ch macros, such as:
#define isdigitch(Anychar) isdigit((u_char)(Anychar))
and then use these whenever some code had been calling
isdigit() with a plain 'char' type. At the point I define
those macros, I include comments as to why I do this, since
this seems to be a pretty common programming mistake. The
mistake usually isn't too bad for isdigit(), but it is more
likely to be serious for some of the other is*() functions.
E.g.:
/*
* All the following take a parameter of 'int', but expect values in the
* range of unsigned char. Define wrappers which take values of type 'char',
* whether signed or unsigned, and ensure they end up in the right range.
*/
#define isdigitch(Anychar) isdigit((u_char)(Anychar))
#define islowerch(Anychar) islower((u_char)(Anychar))
#define isupperch(Anychar) isupper((u_char)(Anychar))
#define tolowerch(Anychar) tolower((u_char)(Anychar))
Note: this is what I do. I am not an OpenBSD developer, and
it wouldn't surprise me if opinions about this varied. But
when I've done it, it's been to FIX code which was using one
of these routines incorrectly. By having these defines, the
programmer only has to type 2 extra characters compared to
the official function, and (IMO) they are more likely to do
that than to remember to do:
islower((unsigned char)somevar)
...particularly if they are not noticing any errors when
using a "plain char" type, because they are only testing
on a hardware-platform where "plain char" is actually the
same as "unsigned char".
Again: I am sure opinions about this will vary quite a bit.
--
Garance Alistair Drosehn = gad
gilead.netel.rpi.edu
Senior Systems Programmer or gad
freebsd.org
Rensselaer Polytechnic Institute or drosih
rpi.edu
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]