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

fix crash on zero-byte torrents

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.