* Fixed the bitstring->unsigned-integer return value with a patch

from David Marmor.


git-svn-id: svn://svn.zoy.org/elk/trunk@172 55e467fa-43c5-0310-a8a2-de718669efc6
This commit is contained in:
sam 2003-09-20 03:25:58 +00:00
parent bae12ce1f8
commit 088f728756
1 changed files with 16 additions and 4 deletions

View File

@ -238,17 +238,29 @@ static Object Bitstring_To_Bignum (Object bs) {
static Object P_Bitstring_To_Int(Object bs) { static Object P_Bitstring_To_Int(Object bs) {
struct S_Bitstring *b; struct S_Bitstring *b;
unsigned u = 0; unsigned int u = 0;
int i; int i;
Check_Type(bs, T_Bitstring); Check_Type(bs, T_Bitstring);
b = BITSTRING(bs); b = BITSTRING(bs);
for (i = bits_to_bytes(b->len) - 1; i >= 0; i--) { /* If there are any 1 bits above the position which fits in an
u = u << 8 | b->data[i]; * integer, use a bignum */
if (!UFIXNUM_FITS(u)) if (b->len >= FIXBITS)
{
if (b->data[sizeof(int) - 1] & (1 << 7))
return Bitstring_To_Bignum(bs);
for (i = sizeof(int); i < (int)bits_to_bytes(b->len); i++) {
if (b->data[i] != 0)
return Bitstring_To_Bignum(bs); return Bitstring_To_Bignum(bs);
} }
}
/* Otherwise, use an integer */
for (i = bits_to_bytes(b->len) - 1; i >= 0; i--)
u = u << 8 | b->data[i];
return Make_Integer(u); return Make_Integer(u);
} }