From: Guillermo J. Rozas Date: Thu, 14 Jun 1990 17:30:32 +0000 (+0000) Subject: Fix bug in bit_string_to_bignum by which the top digit was not masked X-Git-Tag: 20090517-FFI~11385 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=ce9b8d571ffa3c3fa9516c0dda03dd439e9bbe48;p=mit-scheme.git Fix bug in bit_string_to_bignum by which the top digit was not masked according to the number of valid bits. Thus the result was larger under certain conditions. --- diff --git a/v7/src/microcode/bitstr.c b/v7/src/microcode/bitstr.c index c5dbfa401..bca8d0f29 100644 --- a/v7/src/microcode/bitstr.c +++ b/v7/src/microcode/bitstr.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/bitstr.c,v 9.42 1990/04/03 19:57:05 jinx Exp $ +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/bitstr.c,v 9.43 1990/06/14 17:30:32 jinx Exp $ Copyright (c) 1987, 1988, 1989, 1990 Massachusetts Institute of Technology @@ -700,26 +700,40 @@ btbs_consumer (result_ptr, digit) return; } +struct bitstr_to_bignm_context +{ + unsigned char *source_ptr; + unsigned int mask; +}; + SCHEME_OBJECT bit_string_to_bignum (nbits, bitstr) long nbits; SCHEME_OBJECT bitstr; { static unsigned int bstb_producer (); - unsigned char * source_ptr = + struct bitstr_to_bignm_context context; + + context.source_ptr = ((unsigned char *) (BIT_STRING_HIGH_PTR (bitstr))); + context.mask = (LOW_MASK (((nbits - 1) % (CHAR_BIT)) + 1)); + return (digit_stream_to_bignum (((nbits + (CHAR_BIT - 1)) / CHAR_BIT), - bstb_producer, (&source_ptr), + bstb_producer, (&context), (1 << CHAR_BIT), 0)); } static unsigned int -bstb_producer (source_ptr) - unsigned char ** source_ptr; +bstb_producer (context) + struct bitstr_to_bignm_context *context; { - return (* (DEC_BIT_STRING_PTR (*source_ptr))); + unsigned int mask; + + mask = context->mask; + context->mask = (LOW_MASK (CHAR_BIT)); + return (mask & (* (DEC_BIT_STRING_PTR (context->source_ptr)))); } /* (UNSIGNED-INTEGER->BIT-STRING length integer)