mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-09-20 13:08:50 +02:00
646d47aacb
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.
35 lines
538 B
C++
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;
|
|
}
|