From 0ae8c14b4b915b318250484eff9a18700cd934c3 Mon Sep 17 00:00:00 2001 From: Andrew Hsieh Date: Mon, 27 Feb 2012 18:50:55 -0800 Subject: [PATCH] Fixed several 64-bit porting issues 1. Use "%zu" instead of "%d" for size_t in printf 2. Variable precision specifier (eg. "%.*s") in printf should be of type int. (iov_len is size_t which is 64-bit when compiled with -m64) 3. Use PRId64 instead of "%lld" to print variables of type int64_t Change-Id: I2be40a6514b5dffa0038d62b9bccc3401b8756e6 --- libs/utils/BlobCache.cpp | 4 ++-- libs/utils/Debug.cpp | 2 +- libs/utils/Static.cpp | 4 ++-- libs/utils/StopWatch.cpp | 8 ++++++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/libs/utils/BlobCache.cpp b/libs/utils/BlobCache.cpp index e52cf2f84..be398ee4e 100644 --- a/libs/utils/BlobCache.cpp +++ b/libs/utils/BlobCache.cpp @@ -183,7 +183,7 @@ size_t BlobCache::getFdCount() const { status_t BlobCache::flatten(void* buffer, size_t size, int fds[], size_t count) const { if (count != 0) { - ALOGE("flatten: nonzero fd count: %d", count); + ALOGE("flatten: nonzero fd count: %zu", count); return BAD_VALUE; } @@ -234,7 +234,7 @@ status_t BlobCache::unflatten(void const* buffer, size_t size, int fds[], mCacheEntries.clear(); if (count != 0) { - ALOGE("unflatten: nonzero fd count: %d", count); + ALOGE("unflatten: nonzero fd count: %zu", count); return BAD_VALUE; } diff --git a/libs/utils/Debug.cpp b/libs/utils/Debug.cpp index f7988ecf1..e8ac983ea 100644 --- a/libs/utils/Debug.cpp +++ b/libs/utils/Debug.cpp @@ -199,7 +199,7 @@ void printHexData(int32_t indent, const void *buf, size_t length, if ((int32_t)length < 0) { if (singleLineBytesCutoff < 0) func(cookie, "\n"); char buf[64]; - sprintf(buf, "(bad length: %d)", length); + sprintf(buf, "(bad length: %zu)", length); func(cookie, buf); return; } diff --git a/libs/utils/Static.cpp b/libs/utils/Static.cpp index bfcb2da45..624e917ae 100644 --- a/libs/utils/Static.cpp +++ b/libs/utils/Static.cpp @@ -57,8 +57,8 @@ protected: virtual status_t writeLines(const struct iovec& vec, size_t N) { //android_writevLog(&vec, N); <-- this is now a no-op - if (N != 1) ALOGI("WARNING: writeLines N=%d\n", N); - ALOGI("%.*s", vec.iov_len, (const char*) vec.iov_base); + if (N != 1) ALOGI("WARNING: writeLines N=%zu\n", N); + ALOGI("%.*s", (int)vec.iov_len, (const char*) vec.iov_base); return NO_ERROR; } }; diff --git a/libs/utils/StopWatch.cpp b/libs/utils/StopWatch.cpp index 595aec359..b1708d62b 100644 --- a/libs/utils/StopWatch.cpp +++ b/libs/utils/StopWatch.cpp @@ -20,6 +20,10 @@ #include #include +/* for PRId64 */ +#define __STDC_FORMAT_MACROS 1 +#include + #include #include #include @@ -39,11 +43,11 @@ StopWatch::~StopWatch() { nsecs_t elapsed = elapsedTime(); const int n = mNumLaps; - ALOGD("StopWatch %s (us): %lld ", mName, ns2us(elapsed)); + ALOGD("StopWatch %s (us): %" PRId64 " ", mName, ns2us(elapsed)); for (int i=0 ; i