Search code examples
c++jsoncpp

Stack corruption with jsoncpp


I am getting stack corruption saying "Run-Time Check Failure #2 - Stack around the variable 'root' was corrupted." with following code:

#include <json/json.h>
#include <fstream>
#include <iostream>
#include <string>

int main() {
  Json::Value root;
  Json::Reader reader;
  ifstream file("input.json");
  if (!reader.parse(file, root)) {
    cout << "Failed to parse configuration\n"
      << reader.getFormattedErrorMessages();
    return 0;
  }

  file.close();
  cout << root << endl;

  return 0;
}

File input.json contains:

[
  {
    "id": "id"
  }
]

Any idea why this may be happening and how can I debug this?

Thanks in advance!!


Solution

  • Reader class in jsoncpp seems outdated. Refer to the latest example on https://github.com/open-source-parsers/jsoncpp/blob/master/example/readFromStream/readFromStream.cpp