fixed disk_io_thread over-allocation

This commit is contained in:
Arvid Norberg 2008-12-03 06:42:53 +00:00
parent 78d0c06728
commit 2d4bdbca7d
1 changed files with 5 additions and 1 deletions

View File

@ -417,7 +417,10 @@ namespace libtorrent
if (end_block == start_block) return -2;
int buffer_size = piece_size - (end_block - 1) * m_block_size + (end_block - start_block - 1) * m_block_size;
// the buffer_size is the size of the buffer we need to read
// all these blocks.
const int buffer_size = (std::min)((end_block - start_block) * m_block_size
, piece_size - start_block * m_block_size);
TORRENT_ASSERT(buffer_size <= piece_size);
TORRENT_ASSERT(buffer_size + start_block * m_block_size <= piece_size);
boost::scoped_array<char> buf;
@ -440,6 +443,7 @@ namespace libtorrent
if (p.blocks[i] == 0) break;
TORRENT_ASSERT(offset <= buffer_size);
TORRENT_ASSERT(piece_offset <= piece_size);
TORRENT_ASSERT(offset + block_size <= buffer_size);
if (buf)
{
std::memcpy(p.blocks[i], buf.get() + offset, block_size);