mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
utility: fix STL string formatter bug
Must reserve a buf size of len+1 before resizing it, else we are 1 byte too short when copying the entire string. Also just clear when 0.
This commit is contained in:
parent
60a3cee531
commit
115b8e214a
@ -1086,14 +1086,20 @@ string FormatV(const char* szFormat, va_list args)
|
||||
assert(iLen >= 0);
|
||||
string result;
|
||||
|
||||
if (iLen < 0)
|
||||
if (iLen <= 0)
|
||||
{
|
||||
result.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
// NOTE: reserve enough buffer size for the string + the terminating
|
||||
// NULL character, then resize it to just the string len so we don't
|
||||
// count the NULL character in the string's size (i.e. when calling
|
||||
// string::size()).
|
||||
result.reserve(iLen+1);
|
||||
result.resize(iLen);
|
||||
std::vsnprintf(&result[0], iLen+sizeof(char), szFormat, args);
|
||||
|
||||
std::vsnprintf(&result[0], iLen+1, szFormat, args);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
Loading…
x
Reference in New Issue
Block a user