Fixing crash on windows when uFormat() is to long

This commit is contained in:
matlabbe
2026-10-11 11:45:52 -07:00
parent 526c422643
commit 05b5661e6b
6 changed files with 37 additions and 4 deletions
+11
View File
@@ -201,3 +201,14 @@ TEST(UConversionTest, UFormat)
EXPECT_NE(result.find("42"), std::string::npos);
}
TEST(UConversionTest, UFormatLongerThanItsFirstBuffer)
{
// Over the 1024 bytes uFormat first tries: formatted whole, not truncated (MSVC's
// checked vsnprintf_s used to abort the process instead).
const std::string longText(3000, 'a');
std::string result = uFormat("%s %d", longText.c_str(), 42);
EXPECT_EQ(result, longText + " 42");
result = uFormat("%s", std::string(1023, 'b').c_str());
EXPECT_EQ(result, std::string(1023, 'b'));
}