From 9fb6c5b1c47e94cc5f26f327fc97e9069abc7ee8 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 10 Dec 2009 04:54:48 +0000 Subject: [PATCH] (trunk libT) #2655: "1.80b1 crash in peer-mgr.c's getPeersToClose()" -- fixed --- libtransmission/bitfield.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/libtransmission/bitfield.c b/libtransmission/bitfield.c index 537528f0a..abd55ea7b 100644 --- a/libtransmission/bitfield.c +++ b/libtransmission/bitfield.c @@ -159,34 +159,29 @@ tr_bitfieldRemRange( tr_bitfield * b, } tr_bitfield* -tr_bitfieldOr( tr_bitfield * a, - const tr_bitfield * b ) +tr_bitfieldOr( tr_bitfield * a, const tr_bitfield * b ) { - uint8_t * ait; - const uint8_t *aend, *bit, *bend; + uint8_t * ait = a->bits; + const uint8_t * aend = ait + a->byteCount; + const uint8_t * bit = b->bits; + const uint8_t * bend = bit + b->byteCount; - for( ait = a->bits, aend = ait + a->byteCount, - bit = b->bits, bend = bit + b->byteCount; - ait != aend && bit != bend; ) - { + while( ait!=aend && bit!=bend ) *ait++ |= *bit++; - } return a; } /* set 'a' to all the flags that were in 'a' but not 'b' */ void -tr_bitfieldDifference( tr_bitfield * a, - const tr_bitfield * b ) +tr_bitfieldDifference( tr_bitfield * a, const tr_bitfield * b ) { - uint8_t * ait; - const uint8_t *aend, *bit; + uint8_t * ait = a->bits; + const uint8_t * aend = ait + a->byteCount; + const uint8_t * bit = b->bits; + const uint8_t * bend = bit + b->byteCount; - assert( a->byteCount == b->byteCount ); - - for( ait = a->bits, bit = b->bits, aend = ait + a->byteCount; - ait != aend; ) + while( ait!=aend && bit!=bend ) *ait++ &= ~( *bit++ ); }