majintao0131 / yaml-cpp

Automatically exported from code.google.com/p/yaml-cpp
MIT License
0 stars 0 forks source link

YAML::Node::Clone() does not work as expected. #65

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
See YamlTest2.cpp (based on the monsters example) 

What is the expected output? What do you see instead?

The clone node object is not the expected deep copy of the original node.
i.e. output from the attached program is:

$ ./YamlTest2
Original node has 3 element(s).
Cloned node has 0 element(s).

What version of the product are you using? On what operating system?

yaml-cpp.0.2.4 compiled using g++ 4.1.2 on RHEL 5.4 

Please provide any additional information below.

Note that the result is the same even if the original node remains in 
scope.

Original issue reported on code.google.com by benjamin...@gmail.com on 8 Mar 2010 at 10:55

Attachments:

GoogleCodeExporter commented 9 years ago
This constructor for Node called by Node::Clone() looks wrong to me:

Node::Node(const Mark& mark, const std::string& anchor, const std::string& tag, 
const Content *pContent)
    : m_mark(mark), m_anchor(anchor), m_tag(tag), m_pContent(0), m_alias(false), 
m_pIdentity(this), m_referenced(false)
{
    if(m_pContent)
        m_pContent = pContent->Clone();
}

The check for the m_pContent pointer will always fail as it's just been 
initialised 
to zero. I assume that this hsould actually be checking passed in pointer 
pContent 
rather than the member variable on the newly constructed node.

Original comment by benjamin...@gmail.com on 8 Mar 2010 at 1:30

GoogleCodeExporter commented 9 years ago
You're right - this has been fixed in the latest revision, but I haven't had 
time to push 
that to a new version on the main page. Sorry about the confusion.

Original comment by jbe...@gmail.com on 8 Mar 2010 at 3:40