Skip to content

Commit ee458d8

Browse files
MarcoFalkejnewbery
authored andcommitted
Add missing const to CAddrMan::Check_()
Also: Always compile the function signature to avoid similar issues in the future.
1 parent d67330d commit ee458d8

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/addrman.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,9 @@ CAddrInfo CAddrMan::Select_(bool newOnly) const
431431
}
432432
}
433433

434-
#ifdef DEBUG_ADDRMAN
435-
int CAddrMan::Check_()
434+
int CAddrMan::Check_() const
436435
{
436+
#ifdef DEBUG_ADDRMAN
437437
AssertLockHeld(cs);
438438

439439
std::unordered_set<int> setTried;
@@ -458,8 +458,10 @@ int CAddrMan::Check_()
458458
return -4;
459459
mapNew[n] = info.nRefCount;
460460
}
461-
if (mapAddr[info] != n)
461+
const auto it{mapAddr.find(info)};
462+
if (it == mapAddr.end() || it->second != n) {
462463
return -5;
464+
}
463465
if (info.nRandomPos < 0 || (size_t)info.nRandomPos >= vRandom.size() || vRandom[info.nRandomPos] != n)
464466
return -14;
465467
if (info.nLastTry < 0)
@@ -478,10 +480,13 @@ int CAddrMan::Check_()
478480
if (vvTried[n][i] != -1) {
479481
if (!setTried.count(vvTried[n][i]))
480482
return -11;
481-
if (mapInfo[vvTried[n][i]].GetTriedBucket(nKey, m_asmap) != n)
483+
const auto it{mapInfo.find(vvTried[n][i])};
484+
if (it == mapInfo.end() || it->second.GetTriedBucket(nKey, m_asmap) != n) {
482485
return -17;
483-
if (mapInfo[vvTried[n][i]].GetBucketPosition(nKey, false, n) != i)
486+
}
487+
if (it->second.GetBucketPosition(nKey, false, n) != i) {
484488
return -18;
489+
}
485490
setTried.erase(vvTried[n][i]);
486491
}
487492
}
@@ -492,8 +497,10 @@ int CAddrMan::Check_()
492497
if (vvNew[n][i] != -1) {
493498
if (!mapNew.count(vvNew[n][i]))
494499
return -12;
495-
if (mapInfo[vvNew[n][i]].GetBucketPosition(nKey, true, n) != i)
500+
const auto it{mapInfo.find(vvNew[n][i])};
501+
if (it == mapInfo.end() || it->second.GetBucketPosition(nKey, true, n) != i) {
496502
return -19;
503+
}
497504
if (--mapNew[vvNew[n][i]] == 0)
498505
mapNew.erase(vvNew[n][i]);
499506
}
@@ -507,9 +514,9 @@ int CAddrMan::Check_()
507514
if (nKey.IsNull())
508515
return -16;
509516

517+
#endif // DEBUG_ADDRMAN
510518
return 0;
511519
}
512-
#endif
513520

514521
void CAddrMan::GetAddr_(std::vector<CAddress>& vAddr, size_t max_addresses, size_t max_pct, std::optional<Network> network) const
515522
{

src/addrman.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -738,19 +738,15 @@ class CAddrMan
738738
void Check() const
739739
EXCLUSIVE_LOCKS_REQUIRED(cs)
740740
{
741-
#ifdef DEBUG_ADDRMAN
742741
AssertLockHeld(cs);
743742
const int err = Check_();
744743
if (err) {
745744
LogPrintf("ADDRMAN CONSISTENCY CHECK FAILED!!! err=%i\n", err);
746745
}
747-
#endif
748746
}
749747

750-
#ifdef DEBUG_ADDRMAN
751748
//! Perform consistency check. Returns an error code or zero.
752749
int Check_() const EXCLUSIVE_LOCKS_REQUIRED(cs);
753-
#endif
754750

755751
/**
756752
* Return all or many randomly selected addresses, optionally by network.

0 commit comments

Comments
 (0)