In the JSONCPP library's documentation ( here ), it says that the function Json::parseFromStream()
accepts a Json::Value *
as one of its arguments. However it results in a segmentation fault as in the following snippet :
void Coco::read_gt(const std::string filename){
if (!file_exists(&filename)){
throw std::invalid_argument("The file " + filename + " ws not found." );
}
Json::CharReaderBuilder builder{};
builder["collectComments"] = false;
Json::Value * value = nullptr;
std::string errs{};
std::ifstream fid(filename);
LOG(INFO) << "HERE";
bool ok = Json::parseFromStream(builder, fid, value, &errs);
std::cout << ok << std::endl;
value->removeMember("licenses");
gt = value;
return;
}
Interestingly when I use a reference as against the documentation, I do not get a segmentation fault as in the following snippet
void Coco::read_gt(const std::string filename){
if (!file_exists(&filename)){
throw std::invalid_argument("The file " + filename + " ws not found." );
}
Json::CharReaderBuilder builder{};
builder["collectComments"] = false;
Json::Value value;
std::string errs{};
std::ifstream fid(filename);
LOG(INFO) << "HERE";
bool ok = Json::parseFromStream(builder, fid, &value, &errs);
std::cout << ok << std::endl;
value->removeMember("licenses");
gt = value;
return;
}
What is the possible reason for this behavior ?