diff --git a/library/MiscUtils.cpp b/library/MiscUtils.cpp index bbb363e10..daaea64df 100644 --- a/library/MiscUtils.cpp +++ b/library/MiscUtils.cpp @@ -67,10 +67,10 @@ std::string stl_vsprintf(const char *fmt, va_list args) { return std::string(&buf[0], rsz); /* Whole string fits to a single line buffer */ std::string rv; // Allocate enough memory for the output and null termination - rv.resize(rsz+1); - rsz = vsnprintf(&rv[0], rv.size(), fmt, args); - if (rsz + 1 < static_cast(rv.size())) - rv.resize(std::max(rsz+1,0)); + rv.resize(rsz); + rsz = vsnprintf(&rv[0], rv.size()+1, fmt, args); + if (rsz < static_cast(rv.size())) + rv.resize(std::max(rsz,0)); return rv; }