From 569a0461f2307c7e7efb38435011e0504322c049 Mon Sep 17 00:00:00 2001 From: beder Date: Tue, 20 Dec 2011 22:19:54 -0600 Subject: [PATCH] Fixed assignment with an empty node (new API) - a segfault that only showed up in debuggable --- include/yaml-cpp/node/impl.h | 4 +++- test/new-api/nodetests.cpp | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/yaml-cpp/node/impl.h b/include/yaml-cpp/node/impl.h index d562161..3120c79 100644 --- a/include/yaml-cpp/node/impl.h +++ b/include/yaml-cpp/node/impl.h @@ -100,7 +100,9 @@ namespace YAML // assignment inline bool Node::is(const Node& rhs) const { - return m_pNode ? m_pNode->is(*rhs.m_pNode) : false; + if(!m_pNode || !rhs.m_pNode) + return false; + return m_pNode->is(*rhs.m_pNode); } template diff --git a/test/new-api/nodetests.cpp b/test/new-api/nodetests.cpp index a215bac..c41afed 100644 --- a/test/new-api/nodetests.cpp +++ b/test/new-api/nodetests.cpp @@ -279,6 +279,13 @@ namespace Test YAML_ASSERT(!!node["foo"]); return true; } + + TEST Reassign() + { + YAML::Node node = YAML::Load("foo"); + node = YAML::Node(); + return true; + } } void RunNodeTest(TEST (*test)(), const std::string& name, int& passed, int& total) { @@ -324,6 +331,7 @@ namespace Test RunNodeTest(&Node::TempMapVariableAlias, "temp map variable alias", passed, total); RunNodeTest(&Node::Bool, "bool", passed, total); RunNodeTest(&Node::AutoBoolConversion, "auto bool conversion", passed, total); + RunNodeTest(&Node::Reassign, "reassign", passed, total); std::cout << "Node tests: " << passed << "/" << total << " passed\n"; return passed == total;