From 44e4a50050ebb063e113e4cbb75a871bdace554e Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Wed, 16 Sep 2015 13:59:34 -0400 Subject: [PATCH] Fix stack bug in upper_bound --- src/ripple/shamap/impl/SHAMap.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ripple/shamap/impl/SHAMap.cpp b/src/ripple/shamap/impl/SHAMap.cpp index a743aef62..7b5cb15c0 100644 --- a/src/ripple/shamap/impl/SHAMap.cpp +++ b/src/ripple/shamap/impl/SHAMap.cpp @@ -501,7 +501,11 @@ SHAMap::peekFirstItem(NodeStack& stack) const stack.push({root_.get(), SHAMapNodeID{}}); SHAMapTreeNode* node = firstBelow(root_.get(), stack); if (!node) + { + while (!stack.empty()) + stack.pop(); return nullptr; + } return node->peekItem().get(); } @@ -604,11 +608,9 @@ SHAMap::upper_bound(uint256 const& id) const auto leaf = static_cast(node); if (leaf->peekItem()->key() > id) return const_iterator(this, leaf->peekItem().get(), std::move(stack)); - stack.pop(); } else { - stack.pop(); auto inner = static_cast(node); for (auto branch = nodeID.selectBranch(id) + 1; branch < 16; ++branch) { @@ -625,6 +627,7 @@ SHAMap::upper_bound(uint256 const& id) const } } } + stack.pop(); } return end(); }