aboutsummaryrefslogtreecommitdiff
path: root/lib/sanitizer_common/tests/sanitizer_printf_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sanitizer_common/tests/sanitizer_printf_test.cc')
-rw-r--r--lib/sanitizer_common/tests/sanitizer_printf_test.cc23
1 files changed, 20 insertions, 3 deletions
diff --git a/lib/sanitizer_common/tests/sanitizer_printf_test.cc b/lib/sanitizer_common/tests/sanitizer_printf_test.cc
index 2c478cc74286..d0b46ac94ff2 100644
--- a/lib/sanitizer_common/tests/sanitizer_printf_test.cc
+++ b/lib/sanitizer_common/tests/sanitizer_printf_test.cc
@@ -103,6 +103,11 @@ TEST(Printf, OverflowPtr) {
EXPECT_EQ(buf[9], 0);
}
+#if defined(_WIN32)
+// Oh well, MSVS headers don't define snprintf.
+# define snprintf _snprintf
+#endif
+
template<typename T>
static void TestAgainstLibc(const char *fmt, T arg1, T arg2) {
char buf[1024];
@@ -115,12 +120,14 @@ static void TestAgainstLibc(const char *fmt, T arg1, T arg2) {
TEST(Printf, MinMax) {
TestAgainstLibc<int>("%d-%d", INT_MIN, INT_MAX); // NOLINT
- TestAgainstLibc<long>("%zd-%zd", LONG_MIN, LONG_MAX); // NOLINT
TestAgainstLibc<unsigned>("%u-%u", 0, UINT_MAX); // NOLINT
- TestAgainstLibc<unsigned long>("%zu-%zu", 0, ULONG_MAX); // NOLINT
TestAgainstLibc<unsigned>("%x-%x", 0, UINT_MAX); // NOLINT
+#if !defined(_WIN32)
+ // %z* format doesn't seem to be supported by MSVS.
+ TestAgainstLibc<long>("%zd-%zd", LONG_MIN, LONG_MAX); // NOLINT
+ TestAgainstLibc<unsigned long>("%zu-%zu", 0, ULONG_MAX); // NOLINT
TestAgainstLibc<unsigned long>("%zx-%zx", 0, ULONG_MAX); // NOLINT
- Report("%zd\n", LONG_MIN);
+#endif
}
TEST(Printf, Padding) {
@@ -136,4 +143,14 @@ TEST(Printf, Padding) {
TestAgainstLibc<int>("%03d - %03d", -12, -1234);
}
+TEST(Printf, Precision) {
+ char buf[1024];
+ uptr len = internal_snprintf(buf, sizeof(buf), "%.*s", 3, "12345");
+ 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);
+}
+
} // namespace __sanitizer