Common/StringUtil: Fix more incorrect usage of va_list

This commit is contained in:
Connor McLaughlin 2020-02-03 13:53:08 +10:00
parent 899a8e0f03
commit 4eadc07629
2 changed files with 10 additions and 3 deletions

View File

@ -328,7 +328,10 @@ void String::AppendFormattedStringVA(const char* FormatString, va_list ArgPtr)
for (;;)
{
int ret = std::vsnprintf(pBuffer, currentBufferSize, FormatString, ArgPtr);
va_list ArgPtrCopy;
va_copy(ArgPtrCopy, ArgPtr);
int ret = std::vsnprintf(pBuffer, currentBufferSize, FormatString, ArgPtrCopy);
va_end(ArgPtrCopy);
if (ret < 0 || ((u32)ret >= (currentBufferSize - 1)))
{
currentBufferSize *= 2;

View File

@ -14,11 +14,15 @@ std::string StdStringFromFormat(const char* format, ...)
std::string StdStringFromFormatV(const char* format, std::va_list ap)
{
std::va_list ap_copy;
va_copy(ap_copy, ap);
#ifdef WIN32
int len = _vscprintf(format, ap);
int len = _vscprintf(format, ap_copy);
#else
int len = std::vsnprintf(nullptr, 0, format, ap);
int len = std::vsnprintf(nullptr, 0, format, ap_copy);
#endif
va_end(ap_copy);
std::string ret;
ret.resize(len);