Ignore:
Timestamp:
Mar 5, 2007, 11:03:38 PM (15 years ago)
Author:
joshe
Message:

Do bounds checking on bitfields.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/completion.c

    r1356 r1534  
    3131    cp                   = malloc( sizeof( tr_completion_t ) );
    3232    cp->tor              = tor;
    33     cp->blockBitfield    = malloc( ( tor->blockCount + 7 ) / 8 );
     33    cp->blockBitfield    = tr_bitfieldNew( tor->blockCount );
    3434    cp->blockDownloaders = malloc( tor->blockCount );
    35     cp->pieceBitfield    = malloc( ( tor->info.pieceCount + 7 ) / 8 );
     35    cp->pieceBitfield    = tr_bitfieldNew( tor->info.pieceCount );
    3636    cp->missingBlocks    = malloc( tor->info.pieceCount * sizeof( int ) );
    3737
     
    4343void tr_cpClose( tr_completion_t * cp )
    4444{
    45     free( cp->blockBitfield );
    46     free( cp->blockDownloaders );
    47     free( cp->pieceBitfield );
    48     free( cp->missingBlocks );
    49     free( cp );
     45    tr_bitfieldFree( cp->blockBitfield );
     46    free(            cp->blockDownloaders );
     47    tr_bitfieldFree( cp->pieceBitfield );
     48    free(            cp->missingBlocks );
     49    free(            cp );
    5050}
    5151
     
    5656
    5757    cp->blockCount = 0;
    58     memset( cp->blockBitfield,    0, ( tor->blockCount + 7 ) / 8 );
     58    tr_bitfieldClear( cp->blockBitfield );
    5959    memset( cp->blockDownloaders, 0, tor->blockCount );
    60     memset( cp->pieceBitfield,    0, ( tor->info.pieceCount + 7 ) / 8 );
     60    tr_bitfieldClear( cp->pieceBitfield );
    6161    for( i = 0; i < tor->info.pieceCount; i++ )
    6262    {
     
    107107}
    108108
    109 uint8_t * tr_cpPieceBitfield( tr_completion_t * cp )
     109tr_bitfield_t * tr_cpPieceBitfield( tr_completion_t * cp )
    110110{
    111111    return cp->pieceBitfield;
     
    196196}
    197197
    198 uint8_t * tr_cpBlockBitfield( tr_completion_t * cp )
     198tr_bitfield_t * tr_cpBlockBitfield( tr_completion_t * cp )
    199199{
    200200    return cp->blockBitfield;
    201201}
    202202
    203 void tr_cpBlockBitfieldSet( tr_completion_t * cp, uint8_t * bitfield )
     203void tr_cpBlockBitfieldSet( tr_completion_t * cp, tr_bitfield_t * bitfield )
    204204{
    205205    tr_torrent_t * tor = cp->tor;
     
    238238    int blockCount, startBlock, endBlock;
    239239    int complete;
    240     uint8_t * bitfield;
     240    tr_bitfield_t * bitfield;
    241241   
    242242    blockCount  = tr_pieceCountBlocks( piece );
Note: See TracChangeset for help on using the changeset viewer.