Ignore:
Timestamp:
Mar 22, 2008, 6:10:59 PM (14 years ago)
Author:
charles
Message:

fix bug that caused very large torrents to crash Transmission

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/completion.c

    r5001 r5329  
    9898    const tr_info * info = &tor->info;
    9999    uint64_t have=0, total=0;
    100     int i;
     100    tr_piece_index_t i;
    101101    tr_completion * cp ;
    102102
     
    138138
    139139int
    140 tr_cpPieceIsComplete( const tr_completion * cp, int piece )
    141 {
    142     assert( piece >= 0 );
     140tr_cpPieceIsComplete( const tr_completion  * cp,
     141                      tr_piece_index_t       piece )
     142{
    143143    assert( piece < cp->tor->info.pieceCount );
    144144    assert( cp->completeBlocks[piece] <= tr_torPieceCountBlocks(cp->tor,piece) );
     
    153153
    154154void
    155 tr_cpPieceAdd( tr_completion * cp, int piece )
     155tr_cpPieceAdd( tr_completion * cp, tr_piece_index_t piece )
    156156{
    157157    const tr_torrent * tor = cp->tor;
    158     const int start = tr_torPieceFirstBlock(tor,piece);
    159     const int end = start + tr_torPieceCountBlocks(tor,piece);
    160     int i;
     158    const tr_block_index_t start = tr_torPieceFirstBlock(tor,piece);
     159    const tr_block_index_t end = start + tr_torPieceCountBlocks(tor, piece);
     160    tr_block_index_t i;
    161161
    162162    for( i=start; i<end; ++i )
     
    165165
    166166void
    167 tr_cpPieceRem( tr_completion * cp, int piece )
     167tr_cpPieceRem( tr_completion * cp, tr_piece_index_t piece )
    168168{
    169169    const tr_torrent * tor = cp->tor;
    170     const int start = tr_torPieceFirstBlock(tor,piece);
    171     const int end = start + tr_torPieceCountBlocks(tor,piece);
    172     int block;
    173 
    174     assert( cp != NULL );
    175     assert( 0 <= piece );
     170    const tr_block_index_t start = tr_torPieceFirstBlock(tor,piece);
     171    const tr_block_index_t end = start + tr_torPieceCountBlocks(tor,piece);
     172    tr_block_index_t block;
     173
     174    assert( cp != NULL );
    176175    assert( piece < tor->info.pieceCount );
    177     assert( 0 <= start );
    178176    assert( start < tor->blockCount );
    179177    assert( start <= end );
     
    198196}
    199197
    200 int tr_cpBlockIsComplete( const tr_completion * cp, int block )
     198int
     199tr_cpBlockIsComplete( const tr_completion * cp, tr_block_index_t block )
    201200{
    202201    return tr_bitfieldHas( cp->blockBitfield, block ) ? 1 : 0;
     
    204203
    205204void
    206 tr_cpBlockAdd( tr_completion * cp, int block )
     205tr_cpBlockAdd( tr_completion * cp, tr_block_index_t block )
    207206{
    208207    const tr_torrent * tor = cp->tor;
     
    210209    if( !tr_cpBlockIsComplete( cp, block ) )
    211210    {
    212         const int piece = tr_torBlockPiece( tor, block );
     211        const tr_piece_index_t piece = tr_torBlockPiece( tor, block );
    213212        const int blockSize = tr_torBlockCountBytes( tor, block );
    214213
     
    241240tr_cpBlockBitfieldSet( tr_completion * cp, tr_bitfield * bitfield )
    242241{
    243     int i;
     242    tr_block_index_t i;
    244243
    245244    assert( cp != NULL );
     
    253252}
    254253
    255 float tr_cpPercentBlocksInPiece( const tr_completion * cp, int piece )
     254float
     255tr_cpPercentBlocksInPiece( const tr_completion * cp, tr_piece_index_t piece )
    256256{
    257257    assert( cp != NULL );
     
    261261
    262262int
    263 tr_cpMissingBlocksInPiece( const tr_completion * cp, int piece )
     263tr_cpMissingBlocksInPiece( const tr_completion * cp, tr_piece_index_t piece )
    264264{
    265265    assert( cp != NULL );
     
    324324    const tr_torrent * tor = cp->tor;
    325325    const tr_info * info = &tor->info;
    326     int i;
     326    tr_piece_index_t i;
    327327
    328328    for( i=0; i<info->pieceCount; ++i )
Note: See TracChangeset for help on using the changeset viewer.