From 54a2747ef305c10d07d8db393125dbcbb461c428 Mon Sep 17 00:00:00 2001 From: Chih-Hung Hsieh Date: Mon, 18 Apr 2016 11:30:55 -0700 Subject: Fix google-runtime-int warnings. Bug: 28220065 Change-Id: Ida199c66692a1638be6990d583d2ed42583fb592 --- applypatch/applypatch.cpp | 2 +- applypatch/imgpatch.cpp | 4 ++-- applypatch/utils.cpp | 20 ++++++++++---------- applypatch/utils.h | 5 +++-- edify/expr.cpp | 7 ++++--- minui/events.cpp | 15 +++++++++------ recovery-refresh.cpp | 2 +- recovery.cpp | 8 ++++---- screen_ui.cpp | 10 +++++----- uncrypt/uncrypt.cpp | 5 +++-- updater/install.cpp | 11 ++++++----- wear_ui.cpp | 10 +++++----- 12 files changed, 53 insertions(+), 46 deletions(-) diff --git a/applypatch/applypatch.cpp b/applypatch/applypatch.cpp index c8594c283..270fde5c4 100644 --- a/applypatch/applypatch.cpp +++ b/applypatch/applypatch.cpp @@ -596,7 +596,7 @@ size_t FreeSpaceForFile(const char* filename) { int CacheSizeCheck(size_t bytes) { if (MakeFreeSpaceOnCache(bytes) < 0) { - printf("unable to make %ld bytes available on /cache\n", (long)bytes); + printf("unable to make %zu bytes available on /cache\n", bytes); return 1; } else { return 0; diff --git a/applypatch/imgpatch.cpp b/applypatch/imgpatch.cpp index 4251c0120..f5aed763d 100644 --- a/applypatch/imgpatch.cpp +++ b/applypatch/imgpatch.cpp @@ -229,8 +229,8 @@ int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size, ssize_t have = temp_data.size() - strm.avail_out; if (sink(temp_data.data(), have, token) != have) { - printf("failed to write %ld compressed bytes to output\n", - (long)have); + printf("failed to write %zd compressed bytes to output\n", + have); return -1; } if (ctx) SHA1_Update(ctx, temp_data.data(), have); diff --git a/applypatch/utils.cpp b/applypatch/utils.cpp index 4a80be75f..fef250f01 100644 --- a/applypatch/utils.cpp +++ b/applypatch/utils.cpp @@ -27,7 +27,7 @@ void Write4(int value, FILE* f) { } /** Write an 8-byte value to f in little-endian order. */ -void Write8(long long value, FILE* f) { +void Write8(int64_t value, FILE* f) { fputc(value & 0xff, f); fputc((value >> 8) & 0xff, f); fputc((value >> 16) & 0xff, f); @@ -52,14 +52,14 @@ int Read4(void* pv) { (unsigned int)p[0]); } -long long Read8(void* pv) { +int64_t Read8(void* pv) { unsigned char* p = reinterpret_cast(pv); - return (long long)(((unsigned long long)p[7] << 56) | - ((unsigned long long)p[6] << 48) | - ((unsigned long long)p[5] << 40) | - ((unsigned long long)p[4] << 32) | - ((unsigned long long)p[3] << 24) | - ((unsigned long long)p[2] << 16) | - ((unsigned long long)p[1] << 8) | - (unsigned long long)p[0]); + return (int64_t)(((uint64_t)p[7] << 56) | + ((uint64_t)p[6] << 48) | + ((uint64_t)p[5] << 40) | + ((uint64_t)p[4] << 32) | + ((uint64_t)p[3] << 24) | + ((uint64_t)p[2] << 16) | + ((uint64_t)p[1] << 8) | + (uint64_t)p[0]); } diff --git a/applypatch/utils.h b/applypatch/utils.h index bc97f1720..1c34edd97 100644 --- a/applypatch/utils.h +++ b/applypatch/utils.h @@ -17,14 +17,15 @@ #ifndef _BUILD_TOOLS_APPLYPATCH_UTILS_H #define _BUILD_TOOLS_APPLYPATCH_UTILS_H +#include #include // Read and write little-endian values of various sizes. void Write4(int value, FILE* f); -void Write8(long long value, FILE* f); +void Write8(int64_t value, FILE* f); int Read2(void* p); int Read4(void* p); -long long Read8(void* p); +int64_t Read8(void* p); #endif // _BUILD_TOOLS_APPLYPATCH_UTILS_H diff --git a/edify/expr.cpp b/edify/expr.cpp index cd1e08726..c34342f76 100644 --- a/edify/expr.cpp +++ b/edify/expr.cpp @@ -286,13 +286,14 @@ Value* LessThanIntFn(const char* name, State* state, int argc, Expr* argv[]) { bool result = false; char* end; - long l_int = strtol(left, &end, 10); + // Parse up to at least long long or 64-bit integers. + int64_t l_int = static_cast(strtoll(left, &end, 10)); if (left[0] == '\0' || *end != '\0') { goto done; } - long r_int; - r_int = strtol(right, &end, 10); + int64_t r_int; + r_int = static_cast(strtoll(right, &end, 10)); if (right[0] == '\0' || *end != '\0') { goto done; } diff --git a/minui/events.cpp b/minui/events.cpp index 3b2262a4b..a6b9671ed 100644 --- a/minui/events.cpp +++ b/minui/events.cpp @@ -49,7 +49,7 @@ static unsigned ev_count = 0; static unsigned ev_dev_count = 0; static unsigned ev_misc_count = 0; -static bool test_bit(size_t bit, unsigned long* array) { +static bool test_bit(size_t bit, unsigned long* array) { // NOLINT return (array[bit/BITS_PER_LONG] & (1UL << (bit % BITS_PER_LONG))) != 0; } @@ -65,7 +65,8 @@ int ev_init(ev_callback input_cb, void* data) { if (dir != NULL) { dirent* de; while ((de = readdir(dir))) { - unsigned long ev_bits[BITS_TO_LONGS(EV_MAX)]; + // Use unsigned long to match ioctl's parameter type. + unsigned long ev_bits[BITS_TO_LONGS(EV_MAX)]; // NOLINT // fprintf(stderr,"/dev/input/%s\n", de->d_name); if (strncmp(de->d_name, "event", 5)) continue; @@ -175,8 +176,9 @@ int ev_get_input(int fd, uint32_t epevents, input_event* ev) { } int ev_sync_key_state(ev_set_key_callback set_key_cb, void* data) { - unsigned long ev_bits[BITS_TO_LONGS(EV_MAX)]; - unsigned long key_bits[BITS_TO_LONGS(KEY_MAX)]; + // Use unsigned long to match ioctl's parameter type. + unsigned long ev_bits[BITS_TO_LONGS(EV_MAX)]; // NOLINT + unsigned long key_bits[BITS_TO_LONGS(KEY_MAX)]; // NOLINT for (size_t i = 0; i < ev_dev_count; ++i) { memset(ev_bits, 0, sizeof(ev_bits)); @@ -203,8 +205,9 @@ int ev_sync_key_state(ev_set_key_callback set_key_cb, void* data) { } void ev_iterate_available_keys(std::function f) { - unsigned long ev_bits[BITS_TO_LONGS(EV_MAX)]; - unsigned long key_bits[BITS_TO_LONGS(KEY_MAX)]; + // Use unsigned long to match ioctl's parameter type. + unsigned long ev_bits[BITS_TO_LONGS(EV_MAX)]; // NOLINT + unsigned long key_bits[BITS_TO_LONGS(KEY_MAX)]; // NOLINT for (size_t i = 0; i < ev_dev_count; ++i) { memset(ev_bits, 0, sizeof(ev_bits)); diff --git a/recovery-refresh.cpp b/recovery-refresh.cpp index 70adc70ee..333367eba 100644 --- a/recovery-refresh.cpp +++ b/recovery-refresh.cpp @@ -92,7 +92,7 @@ static ssize_t logrotate( if (!isdigit(number.data()[0])) { name += ".1"; } else { - unsigned long long i = std::stoull(number); + auto i = std::stoull(number); name = sub + "." + std::to_string(i + 1); } } diff --git a/recovery.cpp b/recovery.cpp index 169413ad5..20c6ca111 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -391,7 +391,7 @@ static void copy_log_file_to_pmsg(const char* source, const char* destination) { } // How much of the temp log we have copied to the copy in cache. -static long tmplog_offset = 0; +static off_t tmplog_offset = 0; static void copy_log_file(const char* source, const char* destination, bool append) { FILE* dest_fp = fopen_path(destination, append ? "a" : "w"); @@ -401,7 +401,7 @@ static void copy_log_file(const char* source, const char* destination, bool appe FILE* source_fp = fopen(source, "r"); if (source_fp != nullptr) { if (append) { - fseek(source_fp, tmplog_offset, SEEK_SET); // Since last write + fseeko(source_fp, tmplog_offset, SEEK_SET); // Since last write } char buf[4096]; size_t bytes; @@ -409,7 +409,7 @@ static void copy_log_file(const char* source, const char* destination, bool appe fwrite(buf, 1, bytes, dest_fp); } if (append) { - tmplog_offset = ftell(source_fp); + tmplog_offset = ftello(source_fp); } check_and_fclose(source_fp, source); } @@ -1213,7 +1213,7 @@ static ssize_t logrotate( if (!isdigit(number.data()[0])) { name += ".1"; } else { - unsigned long long i = std::stoull(number); + auto i = std::stoull(number); name = sub + "." + std::to_string(i + 1); } } diff --git a/screen_ui.cpp b/screen_ui.cpp index 522aa6b23..1d33269d2 100644 --- a/screen_ui.cpp +++ b/screen_ui.cpp @@ -356,7 +356,7 @@ void ScreenRecoveryUI::ProgressThreadLoop() { // minimum of 20ms delay between frames double delay = interval - (end-start); if (delay < 0.02) delay = 0.02; - usleep((long)(delay * 1000000)); + usleep(static_cast(delay * 1000000)); } } @@ -572,8 +572,8 @@ void ScreenRecoveryUI::ClearText() { } void ScreenRecoveryUI::ShowFile(FILE* fp) { - std::vector offsets; - offsets.push_back(ftell(fp)); + std::vector offsets; + offsets.push_back(ftello(fp)); ClearText(); struct stat sb; @@ -583,7 +583,7 @@ void ScreenRecoveryUI::ShowFile(FILE* fp) { while (true) { if (show_prompt) { PrintOnScreenOnly("--(%d%% of %d bytes)--", - static_cast(100 * (double(ftell(fp)) / double(sb.st_size))), + static_cast(100 * (double(ftello(fp)) / double(sb.st_size))), static_cast(sb.st_size)); Redraw(); while (show_prompt) { @@ -602,7 +602,7 @@ void ScreenRecoveryUI::ShowFile(FILE* fp) { if (feof(fp)) { return; } - offsets.push_back(ftell(fp)); + offsets.push_back(ftello(fp)); } } ClearText(); diff --git a/uncrypt/uncrypt.cpp b/uncrypt/uncrypt.cpp index 43a2c2ab4..a1de6a182 100644 --- a/uncrypt/uncrypt.cpp +++ b/uncrypt/uncrypt.cpp @@ -200,8 +200,9 @@ static int produce_block_map(const char* path, const char* map_file, const char* std::vector ranges; - std::string s = android::base::StringPrintf("%s\n%" PRId64 " %ld\n", - blk_dev, sb.st_size, static_cast(sb.st_blksize)); + std::string s = android::base::StringPrintf("%s\n%" PRId64 " %" PRId64 "\n", + blk_dev, static_cast(sb.st_size), + static_cast(sb.st_blksize)); if (!android::base::WriteStringToFd(s, mapfd)) { ALOGE("failed to write %s: %s", tmp_map_file.c_str(), strerror(errno)); return -1; diff --git a/updater/install.cpp b/updater/install.cpp index 925604f31..4f5268401 100644 --- a/updater/install.cpp +++ b/updater/install.cpp @@ -602,8 +602,8 @@ Value* PackageExtractFileFn(const char* name, State* state, v->size = mzGetZipEntryUncompLen(entry); v->data = reinterpret_cast(malloc(v->size)); if (v->data == NULL) { - printf("%s: failed to allocate %ld bytes for %s\n", - name, (long)v->size, zip_path); + printf("%s: failed to allocate %zd bytes for %s\n", + name, v->size, zip_path); goto done1; } @@ -992,7 +992,8 @@ Value* FileGetPropFn(const char* name, State* state, int argc, Expr* argv[]) { buffer = reinterpret_cast(malloc(st.st_size+1)); if (buffer == NULL) { - ErrorAbort(state, "%s: failed to alloc %lld bytes", name, (long long)st.st_size+1); + ErrorAbort(state, "%s: failed to alloc %zu bytes", name, + static_cast(st.st_size+1)); goto done; } @@ -1004,8 +1005,8 @@ Value* FileGetPropFn(const char* name, State* state, int argc, Expr* argv[]) { } if (ota_fread(buffer, 1, st.st_size, f) != static_cast(st.st_size)) { - ErrorAbort(state, "%s: failed to read %lld bytes from %s", - name, (long long)st.st_size+1, filename); + ErrorAbort(state, "%s: failed to read %zu bytes from %s", + name, static_cast(st.st_size), filename); ota_fclose(f); goto done; } diff --git a/wear_ui.cpp b/wear_ui.cpp index 50aeb3849..48278ff21 100644 --- a/wear_ui.cpp +++ b/wear_ui.cpp @@ -320,7 +320,7 @@ void WearRecoveryUI::progress_loop() { // minimum of 20ms delay between frames double delay = interval - (end-start); if (delay < 0.02) delay = 0.02; - usleep((long)(delay * 1000000)); + usleep(static_cast(delay * 1000000)); } } @@ -573,8 +573,8 @@ void WearRecoveryUI::Redraw() } void WearRecoveryUI::ShowFile(FILE* fp) { - std::vector offsets; - offsets.push_back(ftell(fp)); + std::vector offsets; + offsets.push_back(ftello(fp)); ClearText(); struct stat sb; @@ -584,7 +584,7 @@ void WearRecoveryUI::ShowFile(FILE* fp) { while (true) { if (show_prompt) { Print("--(%d%% of %d bytes)--", - static_cast(100 * (double(ftell(fp)) / double(sb.st_size))), + static_cast(100 * (double(ftello(fp)) / double(sb.st_size))), static_cast(sb.st_size)); Redraw(); while (show_prompt) { @@ -603,7 +603,7 @@ void WearRecoveryUI::ShowFile(FILE* fp) { if (feof(fp)) { return; } - offsets.push_back(ftell(fp)); + offsets.push_back(ftello(fp)); } } ClearText(); -- cgit v1.2.3