Changeset 2070


Ignore:
Timestamp:
Jun 13, 2007, 7:53:10 PM (15 years ago)
Author:
charles
Message:

fix off-by-one crasher reported by floam

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/file_selection/libtransmission/torrent.c

    r2065 r2070  
    604604{
    605605    const tr_file_t * file = &tor->info.files[fileIndex];
    606     int firstBlock         =  file->offset                 / tor->blockSize;
    607     int firstBlockOffset   =  file->offset                 % tor->blockSize;
    608     int lastBlock          = (file->offset + file->length) / tor->blockSize;
    609     int lastBlockOffset    = (file->offset + file->length) % tor->blockSize;
     606    int firstBlock         =  file->offset                     / tor->blockSize;
     607    int firstBlockOffset   =  file->offset                     % tor->blockSize;
     608    int lastBlock          = (file->offset + file->length - 1) / tor->blockSize;
     609    int lastBlockOffset    = (file->offset + file->length - 1) % tor->blockSize;
    610610    size_t haveBytes = 0;
    611611
     612    assert( tor != NULL );
     613    assert( 0<=fileIndex && fileIndex<tor->info.fileCount );
     614    assert( file->offset + file->length <= tor->info.totalSize );
     615    assert( 0<=firstBlock && firstBlock<tor->blockCount );
     616    assert( 0<=lastBlock && lastBlock<tor->blockCount );
     617    assert( firstBlock <= lastBlock );
    612618    assert( tr_blockPiece( firstBlock ) == file->firstPiece );
    613619    assert( tr_blockPiece( lastBlock ) == file->lastPiece );
     
    10681074    file = &info->files[fileIndex];
    10691075    firstByte = file->offset;
    1070     lastByte = firstByte + file->length;
     1076    lastByte = firstByte + file->length - 1;
    10711077    file->firstPiece = getBytePiece( info, firstByte );
    10721078    file->lastPiece = getBytePiece( info, lastByte );
Note: See TracChangeset for help on using the changeset viewer.