diff --git a/include/WinStd/Common.h b/include/WinStd/Common.h index df028a1b..92e721a1 100644 --- a/include/WinStd/Common.h +++ b/include/WinStd/Common.h @@ -261,7 +261,7 @@ static int vsprintf(_Inout_ std::basic_string &str, _In_z_ _ int count = _vsnprintf(buf, _countof(buf), format, arg); if (0 <= count && count < _countof(buf)) { // Copy from stack. - str.append(buf, count); + str.assign(buf, count); return count; } if (count < 0) { @@ -275,9 +275,8 @@ static int vsprintf(_Inout_ std::basic_string &str, _In_z_ _ default: throw std::runtime_error("failed to format string"); } } - size_t offset = str.size(); - str.resize(offset + count); - if (_vsnprintf(&str[offset], static_cast(count) + 1, format, arg) != count) + str.resize(count); + if (_vsnprintf(&str[0], static_cast(count) + 1, format, arg) != count) throw std::runtime_error("failed to format string"); return count; } @@ -300,7 +299,7 @@ static int vsprintf(_Inout_ std::basic_string &str, _In_z int count = _vsnwprintf(buf, _countof(buf), format, arg); if (0 <= count && count < _countof(buf)) { // Copy from stack. - str.append(buf, count); + str.assign(buf, count); return count; } if (count < 0) { @@ -314,9 +313,8 @@ static int vsprintf(_Inout_ std::basic_string &str, _In_z default: throw std::runtime_error("failed to format string"); } } - size_t offset = str.size(); - str.resize(offset + count); - if (_vsnwprintf(&str[offset], static_cast(count) + 1, format, arg) != count) + str.resize(count); + if (_vsnwprintf(&str[0], static_cast(count) + 1, format, arg) != count) throw std::runtime_error("failed to format string"); return count; }