Skip to content

Coredump in jsoncons::jsonpath::json_replace() #430

@wbangna

Description

@wbangna

The following code leads to a coredump:

  jsoncons::ojson doc = jsoncons::ojson::parse(R"({"value":{"value":"long______________enough"}})");

  jsoncons::jsonpath::json_replace(doc, "$..value",
      [](const jsoncons::ojson& match) {
        return jsoncons::ojson {"XXX"};
      });

It works when the json_replace() overload that takes a value instead of a function is used:

  jsoncons::ojson doc = jsoncons::ojson::parse(R"({"value":{"value":"long______________enough"}})");

  jsoncons::jsonpath::json_replace(doc, "$..value", jsoncons::ojson {"XXX"});

Interestingly the coredump disappears when the inner "value" is rewriten first:

  jsoncons::ojson doc = jsoncons::ojson::parse(R"({"value":{"value":"long______________enough"}})");

  jsoncons::jsonpath::json_replace(doc, "$..value..value",
      [](const jsoncons::ojson& match) {
        return jsoncons::ojson {"XXX"};
      });
  std::cout << doc << '\n';

  // now this works! 
  jsoncons::jsonpath::json_replace(doc, "$..value",
      [](const jsoncons::ojson& match) {
        return jsoncons::ojson {"XXX"};
      });
  • Compiler: g++ (GCC) 13.1.1 20230429
  • Architecture: x64
  • Operating system: Arch Linux

This bug was discovered in the release version 0.168.7 and reproduced on the current master

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions