@@ -750,16 +750,14 @@ std::pair<CAddress, int64_t> AddrManImpl::Select_(bool new_only, std::optional<N
750750
751751 // Iterate over the positions of that bucket, starting at the initial one,
752752 // and looping around.
753- int i;
753+ int i, position, node_id ;
754754 for (i = 0 ; i < ADDRMAN_BUCKET_SIZE; ++i) {
755- int position = (initial_position + i) % ADDRMAN_BUCKET_SIZE;
756- int node_id = GetEntry (search_tried, bucket, position);
755+ position = (initial_position + i) % ADDRMAN_BUCKET_SIZE;
756+ node_id = GetEntry (search_tried, bucket, position);
757757 if (node_id != -1 ) {
758758 if (network.has_value ()) {
759759 const auto it{mapInfo.find (node_id)};
760- assert (it != mapInfo.end ());
761- const auto info{it->second };
762- if (info.GetNetwork () == *network) break ;
760+ if (Assume (it != mapInfo.end ()) && it->second .GetNetwork () == *network) break ;
763761 } else {
764762 break ;
765763 }
@@ -770,9 +768,7 @@ std::pair<CAddress, int64_t> AddrManImpl::Select_(bool new_only, std::optional<N
770768 if (i == ADDRMAN_BUCKET_SIZE) continue ;
771769
772770 // Find the entry to return.
773- int position = (initial_position + i) % ADDRMAN_BUCKET_SIZE;
774- int nId = GetEntry (search_tried, bucket, position);
775- const auto it_found{mapInfo.find (nId)};
771+ const auto it_found{mapInfo.find (node_id)};
776772 assert (it_found != mapInfo.end ());
777773 const AddrInfo& info{it_found->second };
778774
@@ -791,15 +787,17 @@ int AddrManImpl::GetEntry(bool use_tried, size_t bucket, size_t position) const
791787{
792788 AssertLockHeld (cs);
793789
794- assert (position < ADDRMAN_BUCKET_SIZE);
795-
796790 if (use_tried) {
797- assert (bucket < ADDRMAN_TRIED_BUCKET_COUNT);
798- return vvTried[bucket][position];
791+ if (Assume (position < ADDRMAN_BUCKET_SIZE) && Assume (bucket < ADDRMAN_TRIED_BUCKET_COUNT)) {
792+ return vvTried[bucket][position];
793+ }
799794 } else {
800- assert (bucket < ADDRMAN_NEW_BUCKET_COUNT);
801- return vvNew[bucket][position];
795+ if (Assume (position < ADDRMAN_BUCKET_SIZE) && Assume (bucket < ADDRMAN_NEW_BUCKET_COUNT)) {
796+ return vvNew[bucket][position];
797+ }
802798 }
799+
800+ return -1 ;
803801}
804802
805803std::vector<CAddress> AddrManImpl::GetAddr_ (size_t max_addresses, size_t max_pct, std::optional<Network> network) const
0 commit comments