add run-time check to file_storage::map_block and improve its documentation
This commit is contained in:
parent
f662b633c3
commit
2a0e64df46
|
@ -334,6 +334,13 @@ namespace libtorrent
|
||||||
// returns a list of file_slice objects representing the portions of
|
// returns a list of file_slice objects representing the portions of
|
||||||
// files the specified piece index, byte offset and size range overlaps.
|
// files the specified piece index, byte offset and size range overlaps.
|
||||||
// this is the inverse mapping of map_file().
|
// this is the inverse mapping of map_file().
|
||||||
|
//
|
||||||
|
// Preconditions of this function is that the input range is within the
|
||||||
|
// torrents address space. ``piece`` may not be negative and
|
||||||
|
//
|
||||||
|
// ``piece`` * piece_size + ``offset`` + ``size``
|
||||||
|
//
|
||||||
|
// may not exceed the total size of the torrent.
|
||||||
std::vector<file_slice> map_block(int piece, boost::int64_t offset
|
std::vector<file_slice> map_block(int piece, boost::int64_t offset
|
||||||
, int size) const;
|
, int size) const;
|
||||||
|
|
||||||
|
|
|
@ -419,7 +419,8 @@ namespace libtorrent
|
||||||
return m_files[index].name_len;
|
return m_files[index].name_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<file_slice> file_storage::map_block(int piece, boost::int64_t offset
|
std::vector<file_slice> file_storage::map_block(int const piece
|
||||||
|
, boost::int64_t const offset
|
||||||
, int size) const
|
, int size) const
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT_PRECOND(num_files() > 0);
|
TORRENT_ASSERT_PRECOND(num_files() > 0);
|
||||||
|
@ -433,6 +434,10 @@ namespace libtorrent
|
||||||
TORRENT_ASSERT_PRECOND(boost::int64_t(target.offset + size) <= m_total_size);
|
TORRENT_ASSERT_PRECOND(boost::int64_t(target.offset + size) <= m_total_size);
|
||||||
TORRENT_ASSERT(!compare_file_offset(target, m_files.front()));
|
TORRENT_ASSERT(!compare_file_offset(target, m_files.front()));
|
||||||
|
|
||||||
|
// in case the size is past the end, fix it up
|
||||||
|
if (boost::int64_t(target.offset + size) > m_total_size)
|
||||||
|
size = m_total_size - target.offset;
|
||||||
|
|
||||||
std::vector<internal_file_entry>::const_iterator file_iter = std::upper_bound(
|
std::vector<internal_file_entry>::const_iterator file_iter = std::upper_bound(
|
||||||
m_files.begin(), m_files.end(), target, compare_file_offset);
|
m_files.begin(), m_files.end(), target, compare_file_offset);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue