jbeder / yaml-cpp

A YAML parser and emitter in C++
MIT License
5.18k stars 1.87k forks source link

Example from tutorial crashes #1294

Closed jesusha123 closed 4 months ago

jesusha123 commented 4 months ago

Steps to reproduce

vcpkg.json file:

{
  "name" : "yaml-crash",
  "version-string" : "0.0.1",
  "builtin-baseline" : "a34c873a9717a888f58dc05268dea15592c2f0ff",
  "dependencies" : [{
    "name" : "yaml-cpp",
    "version>=" : "0.8.0#1"
  }]
}

main.cpp file:

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

int main()
{
    YAML::Node node;  // starts out as null
    node["key"] = "value";  // it now is a map node
    node["seq"].push_back("first element");  // node["seq"] automatically becomes a sequence
    node["seq"].push_back("second element");

    node["mirror"] = node["seq"][0];  // this creates an alias
    node["seq"][0] = "1st element";  // this also changes node["mirror"]
    node["mirror"] = "element #1";  // and this changes node["seq"][0] - they're really the "same" node

    node["self"] = node;  // you can even create self-aliases
    node[node["mirror"]] = node["seq"];  // and strange loops :)
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

CMakeLists.txt file:

cmake_minimum_required(VERSION 3.28)
project(yaml_crash)

set(CMAKE_CXX_STANDARD 23)

find_package(yaml-cpp REQUIRED)

add_executable(yaml_crash main.cpp)

target_link_libraries(yaml_crash
    yaml-cpp::yaml-cpp
)

Observed results

Process finished with exit code -1073741819 (0xC0000005)

image

Expected result

Not to crash

System

jbeder commented 4 months ago

This is crashing on the second line? This one:

node["key"] = "value";  // it now is a map node

If so, I strongly suspect this is an issue with your setup, since there are unit tests that cover this basic use case. Could you take a closer look, and maybe ask on Stack Overflow?

jesusha123 commented 4 months ago

I have a CLion debug configuration, and I switched the vcpkg triplet from x64-windows-release to x64-windows.

Based on the last comment, I suspected debug configurations do not work well with the x64-windows-release vcpkg triplet. It works now, although I don't understand why. I may take a look at this in the future.

I use another library, libcurl with x64-windows-release with CLion debug configuration and it works fine.

Anyways, thank you so much for your quick response.