On Tue, Apr 14, 2009 at 06:37:49PM +0100, lostgallifreyan wrote:
> Dave Dodge <[email protected]> wrote:
> >If the filename string contains any high-valued characters, such as
> >accented letters, then accessing it with a char* might produce a
> >negative char value, and passing that to isupper/islower can be a
> >problem.
>
> Ok. Point taken about undefined behaviour. Is the "unsigned char *p"
> declaration enough though?
Yes. Dereferencing a valid (unsigned char *) will produce an
(unsigned char), which by definition is safe to pass to isupper.
> One mail suggested using "unsigned" at every subsequent use of the
> variable.
That's because p was a (char *), and therefore *p was producing a
possibly-signed value. Casting the dereferenced value to (unsigned
char) is another way of ensuring isupper gets a usable value, but I
think simply changing p to an (unsigned char *) is cleaner.
BTW it's worth noting that casting from a signed integer to an
unsigned integer is a well-defined operation, but casting from
unsigned to signed is implementation-defined.
-Dave Dodge
_______________________________________________
Tinycc-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/tinycc-devel