revert broken commit. Isaac doesn't know what he's doing.

This commit is contained in:
Isaac Connor 2022-01-10 18:47:26 -05:00
parent a0c34f0d96
commit cb30f7639f
1 changed files with 10 additions and 8 deletions

View File

@ -120,16 +120,18 @@ std::string Join(const StringVector &values, const std::string &delim) {
std::string stringtf(const char* format, ...) { std::string stringtf(const char* format, ...) {
va_list args; va_list args;
va_start(args, format); va_start(args, format);
int size = vsnprintf(nullptr, 0, format, args) + 1; // Extra space for '\0'
va_end(args);
if (size <= 0) {
throw std::runtime_error("Error during formatting.");
}
std::unique_ptr<char[]> buf(new char[size]);
va_list args2; va_list args2;
va_copy(args2, args); va_copy(args2, args);
int size = vsnprintf(nullptr, 0, format, args);
va_end(args);
if (size < 0) {
va_end(args2);
throw std::runtime_error("Error during formatting.");
}
size += 1; // Extra space for '\0'
std::unique_ptr<char[]> buf(new char[size]);
vsnprintf(buf.get(), size, format, args2); vsnprintf(buf.get(), size, format, args2);
va_end(args2); va_end(args2);