aboutsummaryrefslogtreecommitdiff
path: root/src/addrman.cpp
diff options
context:
space:
mode:
authorbrunoerg <brunoely.gc@gmail.com>2024-11-07 08:34:16 -0300
committerbrunoerg <brunoely.gc@gmail.com>2024-11-11 12:47:53 -0300
commit9c5775c331e02dab06c78ecbb58488542d16dda7 (patch)
tree270a37db97675100ed3f0d1b1b22224e987d91fd /src/addrman.cpp
parent2c90f8e08c4cf44d4c1ef3dde0e7f7991b8b9390 (diff)
addrman: cap the `max_pct` to not exceed the maximum number of addresses
Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
Diffstat (limited to 'src/addrman.cpp')
-rw-r--r--src/addrman.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/addrman.cpp b/src/addrman.cpp
index 43e7b6a32c..9c3a24db90 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -812,9 +812,11 @@ nid_type AddrManImpl::GetEntry(bool use_tried, size_t bucket, size_t position) c
std::vector<CAddress> AddrManImpl::GetAddr_(size_t max_addresses, size_t max_pct, std::optional<Network> network, const bool filtered) const
{
AssertLockHeld(cs);
+ Assume(max_pct <= 100);
size_t nNodes = vRandom.size();
if (max_pct != 0) {
+ max_pct = std::min(max_pct, size_t{100});
nNodes = max_pct * nNodes / 100;
}
if (max_addresses != 0) {