From ef9c6dc6b373da8d79a1c48b90254404d91f78d7 Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Wed, 4 Oct 2017 00:06:13 +0900 Subject: [PATCH] UnicodeString.cpp: Fix crash when generating HTML report. --- Src/Common/UnicodeString.cpp | 2 +- Testing/GoogleTest/UnicodeString/UnicodeString_test.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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