Bugfix. In edge cases (such as a tree no inner nodes), walkTo could return

a node that shouldn't be returned.
This commit is contained in:
JoelKatz
2012-05-08 19:52:57 -07:00
parent 53ab026af4
commit 71b61a633d

View File

@@ -87,8 +87,7 @@ SHAMapTreeNode::pointer SHAMap::checkCacheNode(const SHAMapNode& iNode)
SHAMapTreeNode::pointer SHAMap::walkTo(const uint256& id, bool modify) SHAMapTreeNode::pointer SHAMap::walkTo(const uint256& id, bool modify)
{ // walk down to the terminal node for this ID { // walk down to the terminal node for this ID
SHAMapTreeNode::pointer inNode = root;
SHAMapTreeNode::pointer inNode=root;
while (!inNode->isLeaf()) while (!inNode->isLeaf())
{ {
@@ -101,6 +100,7 @@ SHAMapTreeNode::pointer SHAMap::walkTo(const uint256& id, bool modify)
if (!nextNode) throw SHAMapException(MissingNode); if (!nextNode) throw SHAMapException(MissingNode);
inNode = nextNode; inNode = nextNode;
} }
if (inNode->getTag() != id) return SHAMapTreeNode::pointer();
if (modify) returnNode(inNode, true); if (modify) returnNode(inNode, true);
return inNode; return inNode;
} }