Fix possible nullptr error

Turns out `vswprintf` doesn't behave like `sprintf` and doesn't return
required buffer size if provided with NULL and 0 buffer length. It's
weird that it worked so far.
This commit is contained in:
zvon 2020-04-16 11:54:44 +02:00
parent 816146e011
commit d2f39eb358

View File

@ -69,9 +69,10 @@ std::wstring LMsg( int id, ... ) {
return local;
va_start( args, id );
int len = vswprintf( nullptr, 0, local, args );
// _vscprintf doesn't count ending '\0'
int len = _vscprintf( local, args ) + 1;
va_end( args );
wchar_t *text = new wchar_t[len + 1];
wchar_t *text = new wchar_t[len];
va_start( args, id );
vswprintf( text, len + 1, local, args );
std::wstring ret = text;