mirror of
https://github.com/roflmuffin/CounterStrikeSharp.git
synced 2025-12-05 23:58:24 -08:00
fix: Invalid string pointers passed by SetResult due to C++ memory lifecycle (#1032)
This commit is contained in:
@@ -199,10 +199,30 @@ class ScriptContext
|
||||
*reinterpret_cast<uint64_t*>(&functionData[0]) = 0;
|
||||
}
|
||||
|
||||
*reinterpret_cast<T*>(&functionData[0]) = value;
|
||||
|
||||
m_numResults = 1;
|
||||
m_numArguments = 0;
|
||||
|
||||
if constexpr (std::is_same_v<T, const char*> || std::is_same_v<T, std::string>)
|
||||
{
|
||||
if constexpr (std::is_same_v<T, const char*>)
|
||||
{
|
||||
if (!value)
|
||||
{
|
||||
*reinterpret_cast<const char**>(&functionData[0]) = nullptr;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static thread_local std::string lastResult;
|
||||
lastResult = value;
|
||||
const char* persistentPtr = lastResult.c_str();
|
||||
|
||||
*reinterpret_cast<const char**>(&functionData[0]) = persistentPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
*reinterpret_cast<T*>(&functionData[0]) = value;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T> inline T GetResult()
|
||||
|
||||
Reference in New Issue
Block a user