Skip to content

Commit

Permalink
assert valid flags in disk interface functions
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn committed Jan 30, 2022
1 parent 98e8415 commit 4f1ac3a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/mmap_disk_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -694,10 +694,22 @@ TORRENT_EXPORT std::unique_ptr<disk_interface> mmap_disk_io_constructor(
? status_t::fatal_disk_error : status_t::no_error;
}

#if TORRENT_USE_ASSERTS
bool valid_flags(disk_job_flags_t const flags)
{
return (flags & ~(disk_interface::force_copy
| disk_interface::sequential_access
| disk_interface::volatile_read
| disk_interface::v1_hash))
== disk_job_flags_t{};
}
#endif

void mmap_disk_io::async_read(storage_index_t storage, peer_request const& r
, std::function<void(disk_buffer_holder, storage_error const&)> handler
, disk_job_flags_t const flags)
{
TORRENT_ASSERT(valid_flags(flags));
TORRENT_ASSERT(r.length <= default_block_size);
TORRENT_ASSERT(r.length > 0);
TORRENT_ASSERT(r.start >= 0);
Expand Down Expand Up @@ -883,6 +895,7 @@ TORRENT_EXPORT std::unique_ptr<disk_interface> mmap_disk_io_constructor(
, piece_index_t const piece, span<sha256_hash> const v2, disk_job_flags_t const flags
, std::function<void(piece_index_t, sha1_hash const&, storage_error const&)> handler)
{
TORRENT_ASSERT(valid_flags(flags));
aux::disk_io_job* j = m_job_pool.allocate_job(aux::job_action_t::hash);
j->storage = m_torrents[storage]->shared_from_this();
j->piece = piece;
Expand All @@ -896,6 +909,7 @@ TORRENT_EXPORT std::unique_ptr<disk_interface> mmap_disk_io_constructor(
, piece_index_t const piece, int const offset, disk_job_flags_t const flags
, std::function<void(piece_index_t, sha256_hash const&, storage_error const&)> handler)
{
TORRENT_ASSERT(valid_flags(flags));
aux::disk_io_job* j = m_job_pool.allocate_job(aux::job_action_t::hash2);
j->storage = m_torrents[storage]->shared_from_this();
j->piece = piece;
Expand Down

0 comments on commit 4f1ac3a

Please sign in to comment.