fix: avoid unintentional map insertions in ActiveRequests::count() (#5520)

This commit is contained in:
Charles Kerr 2023-05-12 20:18:26 -05:00 committed by GitHub
parent 7cabeff24f
commit 69fc149f07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -200,7 +200,9 @@ bool ActiveRequests::has(tr_block_index_t block, tr_peer const* peer) const
// count how many peers we're asking for `block`
size_t ActiveRequests::count(tr_block_index_t block) const
{
return std::size(impl_->blocks_[block]);
auto const& blocks = impl_->blocks_;
auto const iter = blocks.find(block);
return iter == std::end(blocks) ? 0U : std::size(iter->second);
}
// count how many active block requests we have to `peer`