diff --git a/Src/Common/UnicodeString.cpp b/Src/Common/UnicodeString.cpp index 9805d014888..7673fa85184 100644 --- a/Src/Common/UnicodeString.cpp +++ b/Src/Common/UnicodeString.cpp @@ -174,7 +174,7 @@ String format_arg_list(const TCHAR *fmt, va_list args) std::vector buffer(length, 0); while (result == -1) { - result = _vsntprintf_s(&buffer[0], length, length, fmt, args); + result = _vsntprintf_s(&buffer[0], length, _TRUNCATE, fmt, args); length *= 2; buffer.resize(length, 0); } diff --git a/Testing/GoogleTest/UnicodeString/UnicodeString_test.cpp b/Testing/GoogleTest/UnicodeString/UnicodeString_test.cpp index 851f69a04cf..7c882699c2f 100644 --- a/Testing/GoogleTest/UnicodeString/UnicodeString_test.cpp +++ b/Testing/GoogleTest/UnicodeString/UnicodeString_test.cpp @@ -354,4 +354,11 @@ namespace EXPECT_NE(0, strutils::compare_nocase(_T("abc"), _T("aDc"))); } + TEST_F(UnicodeStringTest, Format1) + { + EXPECT_TRUE(String(255, ' ') == strutils::format(_T("%s"), String(255, ' ').c_str())); + EXPECT_TRUE(String(256, ' ') == strutils::format(_T("%s"), String(256, ' ').c_str())); + EXPECT_TRUE(String(257, ' ') == strutils::format(_T("%s"), String(257, ' ').c_str())); + } + } // namespace