Fix up ssprintf.

master
Glenn Maynard 7 years ago
parent 9b6eb07e0b
commit 78d6be9341
  1. 25
      sdk/Windows/Helpers.cpp

@ -68,27 +68,12 @@ wstring SMX::GetErrorString(int err)
string SMX::vssprintf(const char *szFormat, va_list argList)
{
string sStr;
char *pBuf = NULL;
int iChars = 128;
int iUsed = 0;
int iTry = 0;
int iChars = vsnprintf(NULL, 0, szFormat, argList);
do
{
// Grow more than linearly (e.g. 512, 1536, 3072, etc)
iChars += iTry * 1024;
delete[] pBuf;
pBuf = new char[iChars];
iUsed = vsnprintf(pBuf, iChars-1, szFormat, argList);
++iTry;
} while(iUsed < 0);
// assign whatever we managed to format
sStr.assign(pBuf, iUsed);
delete[] pBuf;
string sStr;
sStr.resize(iChars+1);
vsnprintf((char *) sStr.data(), iChars+1, szFormat, argList);
sStr.resize(iChars);
return sStr;
}

Loading…
Cancel
Save