UI: Copy va_list in strprintf on non-Windows
On operating systems other than Windows, va_list has to be copied when you pass it to a new function otherwise it becomes corruptedmaster
parent
2ca0e7cc1a
commit
896de392cd
|
@ -4,22 +4,29 @@
|
|||
|
||||
std::string vstrprintf(const char *format, va_list args)
|
||||
{
|
||||
va_list args2;
|
||||
|
||||
if (!format)
|
||||
return std::string();
|
||||
|
||||
va_copy(args2, args);
|
||||
|
||||
std::string str;
|
||||
int size = (int)vsnprintf(nullptr, 0, format, args) + 1;
|
||||
int size = (int)vsnprintf(nullptr, 0, format, args2) + 1;
|
||||
str.resize(size);
|
||||
vsnprintf(&str[0], size, format, args);
|
||||
vsnprintf(&str[0], size, format, args2);
|
||||
|
||||
va_end(args2);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
std::string strprintf(const char *format, ...)
|
||||
{
|
||||
std::string str;
|
||||
va_list args;
|
||||
|
||||
va_start(args, format);
|
||||
std::string str;
|
||||
str = vstrprintf(format, args);
|
||||
va_end(args);
|
||||
|
||||
|
|
Loading…
Reference in New Issue