diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 4cef980c6..e7f6ea884 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -403,12 +403,11 @@ tr_torrentInitFilePieces( tr_torrent * tor ) /* build the array of first-file hints to give calculatePiecePriority */ firstFiles = tr_new( int, inf->pieceCount ); for( p=f=0; ppieceCount; ++p ) { - if( inf->files[f].lastPiece < p ) + while( inf->files[f].lastPiece < p ) ++f; firstFiles[p] = f; } - #if 0 /* test to confirm the first-file hints are correct */ for( p=0; ppieceCount; ++p ) { @@ -417,6 +416,10 @@ tr_torrentInitFilePieces( tr_torrent * tor ) assert( inf->files[f].lastPiece >= p ); if( f > 0 ) assert( inf->files[f-1].lastPiece < p ); + for( f=0; ffileCount; ++f ) + if( pieceHasFile( p, &inf->files[f] ) ) + break; + assert( (int)f == firstFiles[p] ); } #endif