kastnermario / yaml-cpp

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

Bus error / segmentation fault on reassigning a Node (new API) #140

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
If a Node is modified, and then reassigned to a new blank Node, I get a bus 
error (32 bit) or a segmentation fault (64 bit).

What steps will reproduce the problem?
The following code yields the problem every time:

#include <yaml-cpp/yaml.h>
#include <iostream>

int main()
{
    YAML::Node node = YAML::Load("foo");
    node = YAML::Node();
    std::cout << "Success.\n";
    return 0;
}

If I assign node = "foo" instead of using Load, I get the same problem.  
Weirdly enough, the following works just fine:

YAML::Node node = YAML::Load("foo");
node = YAML::Load("bar");

What is the expected output? What do you see instead?
I'd expect "Success."; instead I get "Bus error" if I compile with 32 bit 
architecture, or "Segmentation fault" if I compile with 64 bit.

What version of the product are you using? On what operating system?
yaml-cpp 0.2.7, compiled with the new API, on Mac OS X 10.5.

Please provide any additional information below.
This isn't really the sort of thing I'd normally want to do; I just happened to 
run into it in some test code.

Original issue reported on code.google.com by geoff.ad...@gmail.com on 21 Dec 2011 at 3:56

GoogleCodeExporter commented 8 years ago
Interesting! I tried replicating this, and I initially was unable to reproduce 
it; but then I compiled with no optimizations (-O0), and it segfaulted, like 
you said. I'll investigate :)

Thanks!

(By the way, I think you must be on some version from the mercurial repository, 
not the 0.2.7 version, since I don't think that release had any new API code.)

Original comment by jbe...@gmail.com on 21 Dec 2011 at 4:14

GoogleCodeExporter commented 8 years ago
Fixed, rc7a8c56abd71.

(It was just a missed null pointer check :)

Let me know if it works for you. Thanks again!

Original comment by jbe...@gmail.com on 21 Dec 2011 at 4:20

GoogleCodeExporter commented 8 years ago
That did the trick! Both 32 and 64 bit versions work fine now. Thanks for the 
speedy response!

And you're right, I am working from the Mercurial repository, not 0.2.7; sorry 
about the misreport! (I just naively read the version from CMakeLists.txt 
without thinking.)

Original comment by geoff.ad...@gmail.com on 21 Dec 2011 at 4:45