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:
parent
816146e011
commit
d2f39eb358
@ -69,9 +69,10 @@ std::wstring LMsg( int id, ... ) {
|
|||||||
return local;
|
return local;
|
||||||
|
|
||||||
va_start( args, id );
|
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 );
|
va_end( args );
|
||||||
wchar_t *text = new wchar_t[len + 1];
|
wchar_t *text = new wchar_t[len];
|
||||||
va_start( args, id );
|
va_start( args, id );
|
||||||
vswprintf( text, len + 1, local, args );
|
vswprintf( text, len + 1, local, args );
|
||||||
std::wstring ret = text;
|
std::wstring ret = text;
|
||||||
|
Loading…
Reference in New Issue
Block a user