DragonFly BSD
DragonFly commits List (threaded) for 2005-07
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: ctype bug


From: Joerg Sonnenberger <joerg@xxxxxxxxxxxxxxxxx>
Date: Thu, 7 Jul 2005 02:56:10 +0200
Mail-followup-to: commits@crater.dragonflybsd.org

On Wed, Jul 06, 2005 at 05:29:11PM -0700, Matthew Dillon wrote:
> 
> :>     No, they never worked like this.  Go back and look at rev 1.1 of
> :>     ctype.h in the FreeBSD source repository.  Guess what it does?  It
> :>     does a range check.
> :
> :Where? It masks the high bits off, there by mapping 255 and -1 to the same value.
> :That's not correct.
> 
>     No, it does a range-check by checking whether the high bits are set
>     (thereby checking the full range AND negative values at the same time),
>     and calls a C procedure instead of blindly indexing the array.  That's
>     my point... the original code was robust, and ours is going to be too.

(a) It was the _FreeBSD_ specific change, not the original code. The original
code *never* did it. That means it was *never* correct to just use a char as
argument.
(b) It slows down well-written code without a reason. Since this macros are
often used in tight loops, that is not a light thing.
(c) It hides programming mistakes.

To summarize, the currrent code does exactly was is portable and follows
the historic practise of anything but FreeBSD. If you want to avoid cast,
check with isascii first. That is also the most basic useage pattern given.
There is no bug in the code, just a bug in the incorrect assumptions about
the interface of this functions. Period.

Joerg



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