From: Michael Lee Date: Thu, 3 Mar 2016 21:14:30 +0000 (-0800) Subject: Fix printing of uint64_t in ConvTest X-Git-Tag: deprecate-dynamic-initializer~15 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=6a7158dc065115cc1644283aff90f63255059eca;p=folly.git 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 --- diff --git a/folly/test/ConvTest.cpp b/folly/test/ConvTest.cpp index 68a40d52..92562080 100644 --- a/folly/test/ConvTest.cpp +++ b/folly/test/ConvTest.cpp @@ -44,18 +44,18 @@ TEST(Conv, digits10) { // try the first X nonnegatives. // Covers some more cases of 2^p, 10^p 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)); } // try powers of 2 power = 1; 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)); - snprintf(buffer, sizeof(buffer), "%lu", power - 1); + snprintf(buffer, sizeof(buffer), "%" PRIu64, 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)); power *= 2; } @@ -63,11 +63,11 @@ TEST(Conv, digits10) { // try powers of 10 power = 1; 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)); - snprintf(buffer, sizeof(buffer), "%lu", power - 1); + snprintf(buffer, sizeof(buffer), "%" PRIu64, 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)); power *= 10; }