bug-m4
[Top][All Lists]
Advanced

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

Re: HEAD: inclusion order wrong for input.c


From: Eric Blake
Subject: Re: HEAD: inclusion order wrong for input.c
Date: Mon, 02 Apr 2007 20:53:11 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.10) Gecko/20070221 Thunderbird/1.5.0.10 Mnenhy/0.7.4.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Gary V. Vaughan on 4/2/2007 4:37 PM:
>> Cast the subscript to unsigned char before using it as index.
>> Otherwise, on a system where char is signed, and its high bit is set,
>> and you haven't adjusted the array range to allow for negative values,
>> fun will ensue.
> 
> If the table value for META-^A is held at element 128 of the array (since
> the table was built assuming char* is unsigned by default), and we compile
> on a host with signed chars, does the signed char value of META-^A still
> become 128 when cast to unsigned char?  Or does 2's complement come into
> play and scramble the order of the negative signed char values when
> casting them before doing a table lookup?

As long as the table is handled consistently (in other words, as long as
ALL uses of characters as indices occur as unsigned char or within
to_uchar), then META-^A (usually encoded as -128 in signed char) will
always appear at the same index, regardless of whether that index is 128
(as it will be on 2's complement machine; the bulk of what exists today),
or 255 (which is what (unsigned char) -128 might become on a 1's
compliment machine, mostly theoretical).  You only run into the bug that
you were describing if you also reference the array based on a given
integer encoding of characters.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGEcGX84KuGfSFAYARAhoWAKCL8gRMEWiFzkIkie/wR8vh64HOnQCgxoxz
Rh5wXLvyWV4uQY5XFYErJBY=
=p822
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]