mirror of
https://github.com/svpcom/wfb-ng.git
synced 2025-02-19 07:03:48 -04:00
Rewrite string_format function #22
This commit is contained in:
parent
2581901a2e
commit
86de92babd
@ -15,8 +15,11 @@ string string_format(const char *format, ...)
|
|||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
size_t size = vsnprintf(nullptr, 0, format, args) + 1; // Extra space for '\0'
|
size_t size = vsnprintf(nullptr, 0, format, args) + 1; // Extra space for '\0'
|
||||||
unique_ptr<char[]> buf(new char[ size ]);
|
va_end(args);
|
||||||
|
unique_ptr<char[]> buf(new char[size]);
|
||||||
|
va_start(args, format);
|
||||||
vsnprintf(buf.get(), size, format, args);
|
vsnprintf(buf.get(), size, format, args);
|
||||||
|
va_end(args);
|
||||||
return string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside
|
return string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user