From bc91fd740fdcbfa168798075cf9d6e322774bca9 Mon Sep 17 00:00:00 2001 From: Edward Hennis Date: Mon, 4 Oct 2021 15:38:33 -0400 Subject: [PATCH] Fix out-of-bounds reserve, and some minor optimizations --- src/ripple/overlay/impl/OverlayImpl.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/ripple/overlay/impl/OverlayImpl.cpp b/src/ripple/overlay/impl/OverlayImpl.cpp index fd2fefc40e..6771db0892 100644 --- a/src/ripple/overlay/impl/OverlayImpl.cpp +++ b/src/ripple/overlay/impl/OverlayImpl.cpp @@ -1164,20 +1164,22 @@ OverlayImpl::getActivePeers( std::lock_guard lock(mutex_); active = ids_.size(); - ret.reserve(ids_.size() - toSkip.size()); + disabled = enabledInSkip = 0; + ret.reserve(ids_.size()); for (auto& [id, w] : ids_) { if (auto p = w.lock()) { - // tx rr feature disabled - if (!p->txReduceRelayEnabled()) - disabled++; + bool const reduceRelayEnabled = p->txReduceRelayEnabled(); + // tx reduced relay feature disabled + if (!reduceRelayEnabled) + ++disabled; if (toSkip.count(id) == 0) ret.emplace_back(std::move(p)); - else if (p->txReduceRelayEnabled()) - enabledInSkip++; + else if (reduceRelayEnabled) + ++enabledInSkip; } }