bada crashed on stringstream read.
json::Object objDocument = d();
std::stringstream stream;
json::Writer::Write(objDocument, stream);
json::Object objDocument2;
json::Reader::Read(objDocument2, stream); // <=== crash
or like this:
std::string *requestString = new std::string(data);
AppLog(requestString->c_str()); // <=== contains correct data
std::stringstream stream;
stream << *requestString;
const char *ddd = stream.str().c_str();
AppLog(ddd); // <==== contains random data
How can I solve it?
Who had ideas or same experience?
The string
stream.str()is a temporary which is destroyed right after you use it to getc_str()after which the pointer is no longer valid.If you save a reference in a temporary the string will stick around: