summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Samsonov <samsonov@google.com>2012-11-02 14:28:17 +0000
committerAlexey Samsonov <samsonov@google.com>2012-11-02 14:28:17 +0000
commit40bd009d5253b3ccfad363230c2d8ac2e139f81f (patch)
treeec8828d5286074e8d5c04ed729f85ca9241216db
parenta517641e8f4365fbc5e3cddf614ebc27efd69c35 (diff)
downloadcompiler-rt-40bd009d5253b3ccfad363230c2d8ac2e139f81f.tar.gz
[Sanitizer] fix printf unittest on 32-bit arch
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@167297 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/sanitizer_common/tests/sanitizer_printf_test.cc26
1 files changed, 22 insertions, 4 deletions
diff --git a/lib/sanitizer_common/tests/sanitizer_printf_test.cc b/lib/sanitizer_common/tests/sanitizer_printf_test.cc
index 7a6a42ea9..b1889cd87 100644
--- a/lib/sanitizer_common/tests/sanitizer_printf_test.cc
+++ b/lib/sanitizer_common/tests/sanitizer_printf_test.cc
@@ -28,8 +28,14 @@ TEST(Printf, Basic) {
(unsigned)10, (unsigned long)11, // NOLINT
(void*)0x123, "_string_");
EXPECT_EQ(len, strlen(buf));
- EXPECT_STREQ("a-1b-2c4294967292e5fahbq"
- "0x000000000123e_string_r", buf);
+ void *ptr;
+ if (sizeof(ptr) == 4) {
+ EXPECT_STREQ("a-1b-2c4294967292e5fahbq"
+ "0x00000123e_string_r", buf);
+ } else {
+ EXPECT_STREQ("a-1b-2c4294967292e5fahbq"
+ "0x000000000123e_string_r", buf);
+ }
}
TEST(Printf, OverflowStr) {
@@ -61,7 +67,13 @@ TEST(Printf, OverflowInt) {
TEST(Printf, OverflowUint) {
char buf[] = "123456789";
- internal_snprintf(buf, 4, "a%zx", (unsigned long)0x123456789); // NOLINT
+ uptr val;
+ if (sizeof(val) == 4) {
+ val = (uptr)0x12345678;
+ } else {
+ val = (uptr)0x123456789ULL;
+ }
+ internal_snprintf(buf, 4, "a%zx", val); // NOLINT
EXPECT_STREQ("a12", buf);
EXPECT_EQ(buf[3], 0);
EXPECT_EQ(buf[4], '5');
@@ -74,7 +86,13 @@ TEST(Printf, OverflowUint) {
TEST(Printf, OverflowPtr) {
char buf[] = "123456789";
- internal_snprintf(buf, 4, "%p", (void*)0x123456789); // NOLINT
+ void *p;
+ if (sizeof(p) == 4) {
+ p = (void*)0x1234567;
+ } else {
+ p = (void*)0x123456789ULL;
+ }
+ internal_snprintf(buf, 4, "%p", p); // NOLINT
EXPECT_STREQ("0x0", buf);
EXPECT_EQ(buf[3], 0);
EXPECT_EQ(buf[4], '5');