diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index a5ed5d84f..aa1960f11 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -687,7 +687,7 @@ blockIteratorNew( Torrent * t ) struct tr_blockIterator * i = tr_new0( struct tr_blockIterator, 1 ); i->t = t; i->pieces = getPreferredPieces( t, &i->pieceCount ); - i->blocks = tr_new0( tr_block_index_t, t->tor->blockCount ); + i->blocks = tr_new0( tr_block_index_t, t->tor->blockCountInPiece ); return i; } @@ -715,6 +715,8 @@ blockIteratorNext( struct tr_blockIterator * i, tr_block_index_t * setme ) i->blocks[i->blockCount++] = block; } + assert( i->blockCount <= tor->blockCountInPiece ); + if(( found = ( i->blockIndex < i->blockCount ))) *setme = i->blocks[i->blockIndex++];