From: Chris Hanson Date: Wed, 25 Jan 1995 20:54:55 +0000 (+0000) Subject: Fix some more fencepost errors in the bit string copying code. X-Git-Tag: 20090517-FFI~6702 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=df651a1bb68a9546000cb88f4ca5e793090ddbe0;p=mit-scheme.git Fix some more fencepost errors in the bit string copying code. --- diff --git a/v7/src/microcode/bitstr.c b/v7/src/microcode/bitstr.c index 7eac1ea74..4e3a0c50e 100644 --- a/v7/src/microcode/bitstr.c +++ b/v7/src/microcode/bitstr.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: bitstr.c,v 9.53 1995/01/24 00:17:25 cph Exp $ +$Id: bitstr.c,v 9.54 1995/01/25 20:54:55 cph Exp $ Copyright (c) 1987-95 Massachusetts Institute of Technology @@ -504,58 +504,43 @@ DEFUN (copy_bits, else { long mask1 = (LOW_MASK (offset1)); - long mask2 = (ANY_MASK (offset2, offset1)); long dest_buffer; { long mask = (ANY_MASK (head, offset1)); dest_buffer - = (((BIT_STRING_WORD (destination)) &~ mask) - | (((* (DEC_BIT_STRING_PTR (source))) << offset1) & mask)); + = (((BIT_STRING_WORD (destination)) + &~ (LOW_MASK (head + offset1))) + | (((* (DEC_BIT_STRING_PTR (source))) & (LOW_MASK (head))) + << offset1)); } nbits -= head; - if (nbits >= OBJECT_LENGTH) + while (nbits >= OBJECT_LENGTH) { - dest_buffer &= mask2; - while (nbits >= OBJECT_LENGTH) - { - (* (DEC_BIT_STRING_PTR (destination))) - = (dest_buffer - | (((BIT_STRING_WORD (source)) >> offset2) & mask1)); - dest_buffer = ((* (DEC_BIT_STRING_PTR (source))) << offset1); - nbits -= OBJECT_LENGTH; - } + (* (DEC_BIT_STRING_PTR (destination))) + = (dest_buffer + | (((BIT_STRING_WORD (source)) >> offset2) & mask1)); + dest_buffer = ((* (DEC_BIT_STRING_PTR (source))) << offset1); + nbits -= OBJECT_LENGTH; } - if (nbits > 0) + if (nbits <= offset1) + (BIT_STRING_WORD (destination)) + = (dest_buffer + | ((BIT_STRING_WORD (destination)) + & (LOW_MASK (offset1 - nbits))) + | (((BIT_STRING_WORD (source)) >> offset2) + & (ANY_MASK (nbits, (offset1 - nbits))))); + else { - if (nbits <= offset1) - { - long mask = (ANY_MASK (nbits, (offset1 - nbits))); - /* This path through copy bits didn't work in certain - cases. The line below seems to fix it. This was an - empirical test, and I don't understand it enough to - tell if it is correct, but I think it is, and I did - a few tests. This is probably what is broken if you - are here poking around trying to fix something. - ~JRM */ - dest_buffer &=~ mask; - (BIT_STRING_WORD (destination)) - = (dest_buffer - | ((BIT_STRING_WORD (destination)) - & (LOW_MASK (offset1 - nbits))) - | (((BIT_STRING_WORD (source)) >> offset2) - & mask)); - } - else - { - long mask; - (* (DEC_BIT_STRING_PTR (destination))) - = (dest_buffer - | (((BIT_STRING_WORD (source)) >> offset2) & mask1)); - mask = (LOW_MASK (OBJECT_LENGTH - nbits)); - (BIT_STRING_WORD (destination)) - = (((BIT_STRING_WORD (destination)) &~ mask) - | (((BIT_STRING_WORD (source)) << offset1) & mask)); - } + (* (DEC_BIT_STRING_PTR (destination))) + = (dest_buffer + | (((BIT_STRING_WORD (source)) >> offset2) & mask1)); + nbits -= offset1; + { + long mask = (LOW_MASK (OBJECT_LENGTH - nbits)); + (BIT_STRING_WORD (destination)) + = (((BIT_STRING_WORD (destination)) & mask) + | (((BIT_STRING_WORD (source)) << offset1) &~ mask)); + } } } }