Ignore:
Timestamp:
Jul 2, 2011, 1:20:17 PM (10 years ago)
Author:
jordan
Message:

(trunk libT) #4336 "availablility nonsense" -- fix bug in tr_cpMissingBytesInPiece() introduced last week by r12515 for #4332. Add assertions to the nightly build to watch for regressions of this fix.

The bug was that I fixed #4332's off-by-one improperly in tr_cpMissingBlocksInPiece(). The piece's last block has to be calculated separately because its byte size may be different than the other blocks, The mistake in r12515 was that the last block could wind up being counted twice.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/completion.c

    r12515 r12531  
    1010 * $Id$
    1111 */
     12
     13#include <assert.h>
    1214
    1315#include "transmission.h"
     
    214216        size_t haveBytes = 0;
    215217        tr_block_index_t f, l;
     218        const size_t pieceByteSize = tr_torPieceCountBytes( cp->tor, piece );
    216219        tr_torGetPieceBlockRange( cp->tor, piece, &f, &l );
    217         haveBytes = tr_bitfieldCountRange( &cp->blockBitfield, f, l+1 );
    218         haveBytes *= cp->tor->blockSize;
    219         if( tr_bitfieldHas( &cp->blockBitfield, l ) )
     220        if( f != l ) {
     221            /* nb: we don't pass the usual l+1 here to tr_bitfieldCountRange().
     222               It's faster to handle the last block separately because its size
     223               needs to be checked separately. */
     224            haveBytes = tr_bitfieldCountRange( &cp->blockBitfield, f, l );
     225            haveBytes *= cp->tor->blockSize;
     226        }
     227        if( tr_bitfieldHas( &cp->blockBitfield, l ) ) /* handle the last block */
    220228            haveBytes += tr_torBlockCountBytes( cp->tor, l );
    221         return tr_torPieceCountBytes( cp->tor, piece ) - haveBytes;
     229        assert(  haveBytes <= pieceByteSize );
     230        return pieceByteSize - haveBytes;
    222231    }
    223232}
Note: See TracChangeset for help on using the changeset viewer.