use vsnprintf instead of snprintf in string_printf function

Also, revert to old location: Utils.hpp and utils.cpp
This commit is contained in:
tamasmeszaros 2020-02-03 11:18:33 +01:00
parent f09bed32b6
commit 0c4797e92e
4 changed files with 24 additions and 18 deletions

View file

@ -577,6 +577,27 @@ namespace PerlUtils {
std::string path_to_parent_path(const char *src) { return boost::filesystem::path(src).parent_path().string(); }
};
std::string string_printf(const char *format, ...)
{
va_list args1;
va_start(args1, format);
va_list args2;
va_copy(args2, args1);
static const size_t INITIAL_LEN = 1024;
std::vector<char> buffer(INITIAL_LEN, '\0');
int bufflen = ::vsnprintf(buffer.data(), INITIAL_LEN - 1, format, args1);
if (bufflen >= int(INITIAL_LEN)) {
buffer.resize(size_t(bufflen) + 1);
::vsnprintf(buffer.data(), buffer.size(), format, args2);
}
return std::string(buffer.begin(), buffer.begin() + bufflen);
}
std::string header_slic3r_generated()
{
return std::string("generated by " SLIC3R_APP_NAME " " SLIC3R_VERSION " on " ) + Utils::utc_timestamp();