Contents changed(cleared?) when access the pointer returned by std::string::c_str()
- by justamask
string conf()
{
vector v;
//..
v = func(); //this function returns a vector
return v[1];
}
void test()
{
const char* p = conf().c_str();
// the string object will be alive as a auto var
// so the pointer should be valid till the end of this function,right?
// ... lots of steps, but none of them would access the pointer p
// when access p here, SOMETIMES the contents would change ... Why?
// the platform is solaris 64 bit
// compiler is sun workshop 12
// my code is compiled as ELF 32-bit MSB relocatable SPARC32PLUS Version 1, V8+ Required
// but need to link with some shared lib which are ELF 32-bit MSB dynamic lib SPARC Version 1, dynamically linked, stripped
}