mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 04:41:16 +00:00
Fixed memory corruption when using a node as a key
This commit is contained in:
@@ -380,6 +380,7 @@ inline const Node Node::operator[](const Node& key) const {
|
|||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
EnsureNodeExists();
|
EnsureNodeExists();
|
||||||
key.EnsureNodeExists();
|
key.EnsureNodeExists();
|
||||||
|
m_pMemory->merge(*key.m_pMemory);
|
||||||
detail::node& value =
|
detail::node& value =
|
||||||
static_cast<const detail::node&>(*m_pNode).get(*key.m_pNode, m_pMemory);
|
static_cast<const detail::node&>(*m_pNode).get(*key.m_pNode, m_pMemory);
|
||||||
return Node(value, m_pMemory);
|
return Node(value, m_pMemory);
|
||||||
@@ -390,6 +391,7 @@ inline Node Node::operator[](const Node& key) {
|
|||||||
throw InvalidNode();
|
throw InvalidNode();
|
||||||
EnsureNodeExists();
|
EnsureNodeExists();
|
||||||
key.EnsureNodeExists();
|
key.EnsureNodeExists();
|
||||||
|
m_pMemory->merge(*key.m_pMemory);
|
||||||
detail::node& value = m_pNode->get(*key.m_pNode, m_pMemory);
|
detail::node& value = m_pNode->get(*key.m_pNode, m_pMemory);
|
||||||
return Node(value, m_pMemory);
|
return Node(value, m_pMemory);
|
||||||
}
|
}
|
||||||
|
@@ -258,5 +258,16 @@ TEST(NodeTest, CloneNull) {
|
|||||||
Node clone = Clone(node);
|
Node clone = Clone(node);
|
||||||
EXPECT_EQ(NodeType::Null, clone.Type());
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user