static void
blocklistLoad( tr_blocklist * b )
{
- int fd;
- struct stat st;
+ int fd;
+ size_t byteCount;
+ struct stat st;
const char * err_fmt = _( "Couldn't read \"%1$s\": %2$s" );
blocklistClose( b );
return;
}
- b->rules = mmap( NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0 );
+ byteCount = (size_t) st.st_size;
+ b->rules = mmap( NULL, byteCount, PROT_READ, MAP_PRIVATE, fd, 0 );
if( !b->rules )
{
tr_err( err_fmt, b->filename, tr_strerror( errno ) );
return;
}
- b->byteCount = st.st_size;
- b->ruleCount = st.st_size / sizeof( struct tr_ip_range );
b->fd = fd;
+ b->byteCount = byteCount;
+ b->ruleCount = byteCount / sizeof( struct tr_ip_range );
{
char * base = tr_basename( b->filename );
***/
tr_blocklist *
-_tr_blocklistNew( const char * filename,
- int isEnabled )
+_tr_blocklistNew( const char * filename, tr_bool isEnabled )
{
tr_blocklist * b;
return list;
}
-static int
+static uint32_t
bestPieceSize( uint64_t totalSize )
{
- const uint64_t GiB = 1073741824;
- const uint64_t MiB = 1048576;
- const uint64_t KiB = 1024;
+ const uint32_t GiB = 1073741824;
+ const uint32_t MiB = 1048576;
+ const uint32_t KiB = 1024;
if( totalSize >= ( 2 * GiB ) ) return 2 * MiB;
if( totalSize >= ( 1 * GiB ) ) return 1 * MiB;
}
while( totalRemain )
{
- uint8_t * bufptr = buf;
- const uint64_t thisPieceSize =
- MIN( (uint32_t)b->pieceSize, totalRemain );
- uint64_t pieceRemain = thisPieceSize;
+ uint8_t * bufptr = buf;
+ const uint32_t thisPieceSize = (uint32_t) MIN( b->pieceSize, totalRemain );
+ uint32_t leftInPiece = thisPieceSize;
assert( b->pieceIndex < b->pieceCount );
- while( pieceRemain )
+ while( leftInPiece )
{
- const uint64_t n_this_pass =
- MIN( ( b->files[fileIndex].size - off ), pieceRemain );
+ const size_t n_this_pass = (size_t) MIN( ( b->files[fileIndex].size - off ), leftInPiece );
read( fd, bufptr, n_this_pass );
bufptr += n_this_pass;
off += n_this_pass;
- pieceRemain -= n_this_pass;
+ leftInPiece -= n_this_pass;
if( off == b->files[fileIndex].size )
{
off = 0;
}
assert( bufptr - buf == (int)thisPieceSize );
- assert( pieceRemain == 0 );
+ assert( leftInPiece == 0 );
tr_sha1( walk, buf, thisPieceSize, NULL );
walk += SHA_DIGEST_LENGTH;