Index: lib/sanitizer_common/sanitizer_printf.cc =================================================================== --- lib/sanitizer_common/sanitizer_printf.cc +++ lib/sanitizer_common/sanitizer_printf.cc @@ -105,6 +105,8 @@ break; result += AppendChar(buff, buff_end, *s); } + while (result < precision) + result += AppendChar(buff, buff_end, ' '); return result; } Index: lib/sanitizer_common/tests/sanitizer_printf_test.cc =================================================================== --- lib/sanitizer_common/tests/sanitizer_printf_test.cc +++ lib/sanitizer_common/tests/sanitizer_printf_test.cc @@ -146,8 +146,13 @@ EXPECT_EQ(3U, len); EXPECT_STREQ("123", buf); len = internal_snprintf(buf, sizeof(buf), "%.*s", 6, "12345"); - EXPECT_EQ(5U, len); - EXPECT_STREQ("12345", buf); + EXPECT_EQ(6U, len); + EXPECT_STREQ("12345 ", buf); + // CHeck that precision does not overflow the smaller buffer, although + // 10 chars is requested, it stops at the buffer size, 8. + len = internal_snprintf(buf, 8, "%.*s", 10, "12345"); + EXPECT_EQ(10U, len); // The required size reported. + EXPECT_STREQ("12345 ", buf); } } // namespace __sanitizer