Changeset 2348


Ignore:
Timestamp:
Jul 15, 2007, 3:52:51 AM (15 years ago)
Author:
charles
Message:

fix crash on zero-byte torrents

Location:
trunk/libtransmission
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/completion.c

    r2316 r2348  
    116116
    117117    cp->completeBlocks[piece] = n_blocks;
    118     tr_bitfieldAddRange( cp->blockBitfield, startBlock, endBlock-1 );
     118    tr_bitfieldAddRange( cp->blockBitfield, startBlock, endBlock );
    119119    tr_bitfieldAdd( cp->pieceBitfield, piece );
    120120}
     
    128128
    129129    cp->completeBlocks[piece] = 0;
    130     tr_bitfieldRemRange ( cp->blockBitfield, startBlock, endBlock-1 );
     130    tr_bitfieldRemRange ( cp->blockBitfield, startBlock, endBlock );
    131131    tr_bitfieldRem( cp->pieceBitfield, piece );
    132132}
     
    323323    b *= tor->blockSize;
    324324
    325     if( !tr_cpBlockIsComplete( cp, tor->blockCount - 1 ) )
    326         b -= (tor->blockSize - (tor->info.totalSize % tor->blockSize));
     325    if( tor->blockCount && !tr_cpBlockIsComplete( cp, tor->blockCount - 1 ) )
     326          b -= (tor->blockSize - (tor->info.totalSize % tor->blockSize));
    327327
    328328    return b;
     
    349349    b *= tor->blockSize;
    350350
    351     i = tor->blockCount - 1;
    352     if( !tr_cpBlockIsComplete( cp, tor->blockCount-1 ) && !info->pieces[info->pieceCount-1].dnd )
    353         b -= (tor->blockSize - (tor->info.totalSize % tor->blockSize));
     351    if( tor->blockCount && !tr_cpBlockIsComplete( cp, tor->blockCount-1 )
     352                        && !info->pieces[info->pieceCount-1].dnd )
     353          b -= (tor->blockSize - (tor->info.totalSize % tor->blockSize));
    354354
    355355    return b;
     
    381381    uint64_t b = tr_bitfieldCountTrueBits( cp->blockBitfield ) * tor->blockSize;
    382382
    383     if( tr_bitfieldHas( cp->blockBitfield, tor->blockCount - 1 ) )
     383    if( tor->blockCount && tr_bitfieldHas( cp->blockBitfield, tor->blockCount - 1 ) )
    384384        b -= (tor->blockSize - (tor->info.totalSize % tor->blockSize));
    385385
  • trunk/libtransmission/fastresume.c

    r2328 r2348  
    301301                        file->name, file->firstPiece, file->lastPiece);
    302302                tr_bitfieldAddRange( uncheckedPieces,
    303                                      file->firstPiece, file->lastPiece );
     303                                     file->firstPiece, file->lastPiece+1 );
    304304            }
    305305        }
  • trunk/libtransmission/inout.c

    r2328 r2348  
    223223
    224224    if( (mode==TR_RECHECK_FORCE) || fastResumeLoad( tor, uncheckedPieces ) )
    225         tr_bitfieldAddRange( uncheckedPieces, 0, tor->info.pieceCount-1 );
     225        tr_bitfieldAddRange( uncheckedPieces, 0, tor->info.pieceCount );
    226226
    227227    if( tr_bitfieldIsEmpty( uncheckedPieces ) ) {
  • trunk/libtransmission/utils.c

    r2340 r2348  
    513513void
    514514tr_bitfieldAddRange( tr_bitfield_t  * bitfield,
    515                      size_t           first,
    516                      size_t           last )
     515                     size_t           begin,
     516                     size_t           end )
    517517{
    518518    /* TODO: there are faster ways to do this */
    519519    unsigned int i;
    520     for( i=first; i<=last; ++i )
     520    for( i=begin; i<end; ++i )
    521521        tr_bitfieldAdd( bitfield, i );
    522522}
     
    535535void
    536536tr_bitfieldRemRange ( tr_bitfield_t  * b,
    537                       size_t           first,
    538                       size_t           last )
     537                      size_t           begin,
     538                      size_t           end )
    539539{
    540540    /* TODO: there are faster ways to do this */
    541541    unsigned int i;
    542     for( i=first; i<=last; ++i )
     542    for( i=begin; i<end; ++i )
    543543        tr_bitfieldRem( b, i );
    544544}
  • trunk/libtransmission/utils.h

    r2341 r2348  
    190190void tr_bitfieldAdd( tr_bitfield_t*, size_t bit );
    191191void tr_bitfieldRem( tr_bitfield_t*, size_t bit );
    192 void tr_bitfieldAddRange( tr_bitfield_t *, size_t first, size_t last );
    193 void tr_bitfieldRemRange ( tr_bitfield_t*, size_t first, size_t last );
     192void tr_bitfieldAddRange( tr_bitfield_t *, size_t begin, size_t end );
     193void tr_bitfieldRemRange ( tr_bitfield_t*, size_t begin, size_t end );
    194194
    195195int    tr_bitfieldIsEmpty( const tr_bitfield_t* );
Note: See TracChangeset for help on using the changeset viewer.