From 42cbbaa57ab272d47c291a6c9918506b2d68d1c6 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 26 Apr 2008 14:52:05 +0000 Subject: [PATCH] fix an assertion error: completion.c:113: failed assertion `ccp->sizeWhenDoneLazy >= ccp->sizeNow' --- libtransmission/completion.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/libtransmission/completion.c b/libtransmission/completion.c index ecea5ff79..d44d3c769 100644 --- a/libtransmission/completion.c +++ b/libtransmission/completion.c @@ -97,13 +97,29 @@ tr_cpSizeWhenDone( const tr_completion * ccp ) if( ccp->sizeWhenDoneIsDirty ) { tr_completion * cp = (tr_completion *) ccp; /* mutable */ - const tr_info * info = &cp->tor->info; + const tr_torrent * tor = cp->tor; + const tr_info * info = &tor->info; tr_piece_index_t i; uint64_t size = 0; for( i=0; ipieceCount; ++i ) - if( !info->pieces[i].dnd || tr_cpPieceIsComplete( cp, i ) ) - size += tr_torPieceCountBytes( cp->tor, i ); + { + if( !info->pieces[i].dnd ) { + // we want the piece... + size += tr_torPieceCountBytes( tor, i ); + } else if( tr_cpPieceIsComplete( cp, i ) ) { + // we have the piece... + size += tr_torPieceCountBytes( tor, i ); + } else if( cp->completeBlocks[i] ) { + // we have part of the piece... + const tr_block_index_t b = tr_torPieceFirstBlock( tor, i ); + const tr_block_index_t e = b + tr_torPieceCountBlocks( tor, i ); + tr_block_index_t j; + for( j=b; jsizeWhenDoneLazy = size; cp->sizeWhenDoneIsDirty = 0;