Skip to content

Traversing the ryml::Tree #245

Answered by biojppm
rizwankadhar asked this question in Q&A
Apr 10, 2022 · 3 comments · 3 replies
Discussion options

You must be logged in to vote

Also I noticed that you're storing the csubstr view into a temporary std::string. That's sure to cause a read-after-free crash.

Do something like this:

struct keyData {
    std::string key; // store as std::string!!!
    std::string parent;
    std::string data;
    keyData() {}
    keyData(ryml::csubstr k, ryml::csubstr p, ryml::csubstr d) : key(k.str, k.len), parent(p.str, p.len), data(d.str, d.len) {}
};
void getstr(ryml::NodeRef node, ryml::csubstr parent, vector<keyData> &vec)
{
    auto getkey = [](NodeRef node){ return node.has_key() ? node.key() : ryml::csubstr{}; };
    auto getval = [](NodeRef node){ return node.has_val() ? node.val() : ryml::csubstr{}; };
    if (!node.has_chil…

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

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

@rizwankadhar
Comment options

@biojppm
Comment options

Answer selected by rizwankadhar
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