Commit 6a7158dc authored by Michael Lee's avatar Michael Lee Committed by Facebook Github Bot 7

Fix printing of uint64_t in ConvTest

Summary:uint64_t is an unsigned long for 64-bit, but a long long int
for 32-bit.  `%lu` can cause truncation in certain implementations of
libc.

Reviewed By: ngoyal

Differential Revision: D3007568

fb-gh-sync-id: bbb1896c9727cbff413ac73ff0caa12bae5d8a6a
shipit-source-id: bbb1896c9727cbff413ac73ff0caa12bae5d8a6a
parent 41e2f6d4
...@@ -44,18 +44,18 @@ TEST(Conv, digits10) { ...@@ -44,18 +44,18 @@ TEST(Conv, digits10) {
// try the first X nonnegatives. // try the first X nonnegatives.
// Covers some more cases of 2^p, 10^p // Covers some more cases of 2^p, 10^p
for (uint64_t i = 0; i < 100000; i++) { for (uint64_t i = 0; i < 100000; i++) {
snprintf(buffer, sizeof(buffer), "%lu", i); snprintf(buffer, sizeof(buffer), "%" PRIu64, i);
EXPECT_EQ(strlen(buffer), digits10(i)); EXPECT_EQ(strlen(buffer), digits10(i));
} }
// try powers of 2 // try powers of 2
power = 1; power = 1;
for (int p = 0; p < 64; p++) { for (int p = 0; p < 64; p++) {
snprintf(buffer, sizeof(buffer), "%lu", power); snprintf(buffer, sizeof(buffer), "%" PRIu64, power);
EXPECT_EQ(strlen(buffer), digits10(power)); EXPECT_EQ(strlen(buffer), digits10(power));
snprintf(buffer, sizeof(buffer), "%lu", power - 1); snprintf(buffer, sizeof(buffer), "%" PRIu64, power - 1);
EXPECT_EQ(strlen(buffer), digits10(power - 1)); EXPECT_EQ(strlen(buffer), digits10(power - 1));
snprintf(buffer, sizeof(buffer), "%lu", power + 1); snprintf(buffer, sizeof(buffer), "%" PRIu64, power + 1);
EXPECT_EQ(strlen(buffer), digits10(power + 1)); EXPECT_EQ(strlen(buffer), digits10(power + 1));
power *= 2; power *= 2;
} }
...@@ -63,11 +63,11 @@ TEST(Conv, digits10) { ...@@ -63,11 +63,11 @@ TEST(Conv, digits10) {
// try powers of 10 // try powers of 10
power = 1; power = 1;
for (int p = 0; p < 20; p++) { for (int p = 0; p < 20; p++) {
snprintf(buffer, sizeof(buffer), "%lu", power); snprintf(buffer, sizeof(buffer), "%" PRIu64, power);
EXPECT_EQ(strlen(buffer), digits10(power)); EXPECT_EQ(strlen(buffer), digits10(power));
snprintf(buffer, sizeof(buffer), "%lu", power - 1); snprintf(buffer, sizeof(buffer), "%" PRIu64, power - 1);
EXPECT_EQ(strlen(buffer), digits10(power - 1)); EXPECT_EQ(strlen(buffer), digits10(power - 1));
snprintf(buffer, sizeof(buffer), "%lu", power + 1); snprintf(buffer, sizeof(buffer), "%" PRIu64, power + 1);
EXPECT_EQ(strlen(buffer), digits10(power + 1)); EXPECT_EQ(strlen(buffer), digits10(power + 1));
power *= 10; power *= 10;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment