0
0
mirror of https://github.com/obsproject/obs-studio.git synced 2024-09-20 13:08:50 +02:00
obs-studio/UI/nix-update/nix-update-helpers.cpp
Jim 646d47aacb UI: Fix non-Windows vstrprintf
vsnprintf is called twice; one call must use args, and one must use
args2 (which is how it was supposed to be from the beginning). Each call
"consumes" its va_list parameter, so they each need to use a separate
copy. Fixes potential corruption and/or crashing when calling vsnprintf.
2022-09-09 23:25:31 -07:00

35 lines
538 B
C++

#include "nix-update-helpers.hpp"
#include <stdarg.h>
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, args2) + 1;
str.resize(size);
vsnprintf(&str[0], size, format, args);
va_end(args2);
return str;
}
std::string strprintf(const char *format, ...)
{
va_list args;
va_start(args, format);
std::string str;
str = vstrprintf(format, args);
va_end(args);
return str;
}