Don't access a C string past precision in printf (#1595)

This commit is contained in:
Victor Zverovich
2020-04-22 16:39:28 -07:00
parent 7d748a6f82
commit 0463665ef1
2 changed files with 19 additions and 0 deletions
+5
View File
@@ -259,6 +259,11 @@ TEST(PrintfTest, FloatPrecision) {
EXPECT_PRINTF(buffer, "%.3a", 1234.5678);
}
TEST(PrintfTest, StringPrecision) {
char test[] = {'H', 'e', 'l', 'l', 'o'};
EXPECT_EQ(fmt::sprintf("%.4s", test), "Hell");
}
TEST(PrintfTest, IgnorePrecisionForNonNumericArg) {
EXPECT_PRINTF("abc", "%.5s", "abc");
}