Skip to content

Segfault when using Tree::merge_with with default constructor #283

Answered by biojppm
captain-yoshi asked this question in Q&A
Discussion options

You must be logged in to vote

@captain-yoshi sorry, missed the update. This one is actually easy. Looking at the definition of .merge_with():

    void merge_with(Tree const* src, size_t src_node=NONE, size_t dst_root=NONE);

It hints that you should use NONE to merge at the root. That also contemplates your situation, specifically about the prior inexistence of root in a default-constructed tree. Looking at the preamble of the function:

void Tree::merge_with(Tree const *src, size_t src_node, size_t dst_node)
{
    _RYML_CB_ASSERT(m_callbacks, src != nullptr);
    if(src_node == NONE)
        src_node = src->root_id();
    if(dst_node == NONE)
        dst_node = root_id();   // <- here. this will mutate and get you a va…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@biojppm
Comment options

Comment options

You must be logged in to vote
2 replies
@biojppm
Comment options

@captain-yoshi
Comment options

Answer selected by captain-yoshi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants