From d4ff55bff7582c57cfa62fa4c522dd47d81ff015 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Tue, 3 Sep 2024 18:23:07 +0100 Subject: [PATCH] Fix negative-wraparound issue when converting size_t to ptrdiff_t which is used by std::views::take. This issue was flagged by VisualStudio debug asserts --- nano/node/repcrawler.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nano/node/repcrawler.cpp b/nano/node/repcrawler.cpp index f6cca66b5f..debb30cd40 100644 --- a/nano/node/repcrawler.cpp +++ b/nano/node/repcrawler.cpp @@ -452,8 +452,9 @@ std::vector nano::rep_crawler::representatives (std::size_ } std::vector result; - for (auto const & [weight, rep] : ordered | std::views::take (count)) + for (auto i = ordered.begin (), n = ordered.end (); i != n && result.size () < count; ++i) { + auto const & [weight, rep] = *i; result.push_back ({ rep.account, rep.channel }); } return result;