diff --git a/fmt/printf.h b/fmt/printf.h index 038b9f26d2db..6ce752e7e3c7 100644 --- a/fmt/printf.h +++ b/fmt/printf.h @@ -439,6 +439,8 @@ void PrintfFormatter::format(BasicCStringRef format_str) { } else if (*s == '*') { ++s; spec.precision_ = internal::PrecisionHandler().visit(get_arg(s)); + } else { + spec.precision_ = 0; } } diff --git a/test/printf-test.cc b/test/printf-test.cc index 7d9e21ddb11c..81a041d776b8 100644 --- a/test/printf-test.cc +++ b/test/printf-test.cc @@ -401,6 +401,9 @@ TEST(PrintfTest, LongLong) { TEST(PrintfTest, Float) { EXPECT_PRINTF("392.650000", "%f", 392.65); + EXPECT_PRINTF("392.65", "%.2f", 392.65); + EXPECT_PRINTF("392.6", "%.1f", 392.65); + EXPECT_PRINTF("393", "%.f", 392.65); EXPECT_PRINTF("392.650000", "%F", 392.65); EXPECT_PRINTF("392.65", "%s", 392.65); char buffer[BUFFER_SIZE];