Commit 2c340f05 authored by Jesse Beder's avatar Jesse Beder
Browse files

Fixed memory corruption when using a node as a key

parent 1aa25e76
......@@ -380,6 +380,7 @@ inline const Node Node::operator[](const Node& key) const {
throw InvalidNode();
EnsureNodeExists();
key.EnsureNodeExists();
m_pMemory->merge(*key.m_pMemory);
detail::node& value =
static_cast<const detail::node&>(*m_pNode).get(*key.m_pNode, m_pMemory);
return Node(value, m_pMemory);
......@@ -390,6 +391,7 @@ inline Node Node::operator[](const Node& key) {
throw InvalidNode();
EnsureNodeExists();
key.EnsureNodeExists();
m_pMemory->merge(*key.m_pMemory);
detail::node& value = m_pNode->get(*key.m_pNode, m_pMemory);
return Node(value, m_pMemory);
}
......
......@@ -258,5 +258,16 @@ TEST(NodeTest, CloneNull) {
Node clone = Clone(node);
EXPECT_EQ(NodeType::Null, clone.Type());
}
TEST(NodeTest, KeyNodeExitsScope) {
Node node;
{
Node temp("Hello, world");
node[temp] = 0;
}
for (const auto &kv : node) {
(void)kv;
}
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment