1
0
mirror of https://github.com/wolfpld/tracy.git synced 2025-03-20 07:40:02 +08:00

Store custom strings as const char*, not std::string.

It would seem that std::string is not moved, but copied, thus
invalidating the pointer.
This commit is contained in:
Bartosz Taudul
2017-09-27 02:36:14 +02:00
parent 537542f682
commit c2926f2a0d
2 changed files with 10 additions and 5 deletions
+8 -4
View File
@@ -385,15 +385,19 @@ void View::AddCustomString( uint64_t ptr, std::string&& str )
{
auto pit = m_pendingCustomStrings.find( ptr );
assert( pit != m_pendingCustomStrings.end() );
auto sit = m_customStrings.find( str );
auto sit = m_customStrings.find( str.c_str() );
if( sit == m_customStrings.end() )
{
pit->second->text = str.c_str();
m_customStrings.emplace( std::move( str ) );
const auto sz = str.size();
auto ptr = new char[sz+1];
memcpy( ptr, str.c_str(), sz );
ptr[sz] = '\0';
pit->second->text = ptr;
m_customStrings.emplace( ptr );
}
else
{
pit->second->text = sit->c_str();
pit->second->text = *sit;
}
m_pendingCustomStrings.erase( pit );
}