From 04b53293451031fbe555db4e4993753f8bc3f368 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 12 May 2023 20:18:26 -0500 Subject: [PATCH] fix: avoid unintentional map insertions in ActiveRequests::count() (#5520) --- libtransmission/peer-mgr-active-requests.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libtransmission/peer-mgr-active-requests.cc b/libtransmission/peer-mgr-active-requests.cc index a5c21dc2b..6bf3bbb4a 100644 --- a/libtransmission/peer-mgr-active-requests.cc +++ b/libtransmission/peer-mgr-active-requests.cc @@ -198,7 +198,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`