From b8df5fb90e4b7244fa7925b9706cdd218e18a2aa Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Tue, 8 Dec 2015 22:47:25 -0800 Subject: uncrypt: Suppress the compiler warnings on LP64. We have the following warnings when compiling uncrypt on LP64 (e.g. aosp_angler-userdebug). bootable/recovery/uncrypt/uncrypt.cpp:77:53: warning: format specifies type 'long long' but the argument has type 'off64_t' (aka 'long') [-Wformat] ALOGE("error seeking to offset %lld: %s\n", offset, strerror(errno)); ~~~~ ^~~~~~ %ld bootable/recovery/uncrypt/uncrypt.cpp:84:54: warning: format specifies type 'long long' but the argument has type 'unsigned long' [-Wformat] ALOGE("error writing offset %lld: %s\n", (offset + written), strerror(errno)); ~~~~ ^~~~~~~~~~~~~~~~~~ %lu bootable/recovery/uncrypt/uncrypt.cpp:246:16: warning: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'off_t' (aka 'long') [-Wsign-compare] while (pos < sb.st_size) { ~~~ ^ ~~~~~~~~~~ According to POSIX spec [1], we have: off_t and blksize_t shall be signed integer types; size_t shall be an unsigned integer type; blksize_t and size_t are no greater than the width of type long. And on Android, we always have a 64-bit st_size from stat(2) (//bionic/libc/include/sys/stat.h). Fix the type and add necessary casts to suppress the warnings. [1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_types.h.html Change-Id: I5d64d5b7919c541441176c364752de047f9ecb20 --- uncrypt/uncrypt.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/uncrypt/uncrypt.cpp b/uncrypt/uncrypt.cpp index 482504192..20efbe4df 100644 --- a/uncrypt/uncrypt.cpp +++ b/uncrypt/uncrypt.cpp @@ -41,6 +41,7 @@ #include #include +#include #include #include #include @@ -74,14 +75,15 @@ static struct fstab* fstab = NULL; static int write_at_offset(unsigned char* buffer, size_t size, int wfd, off64_t offset) { if (TEMP_FAILURE_RETRY(lseek64(wfd, offset, SEEK_SET)) == -1) { - ALOGE("error seeking to offset %lld: %s\n", offset, strerror(errno)); + ALOGE("error seeking to offset %" PRId64 ": %s\n", offset, strerror(errno)); return -1; } size_t written = 0; while (written < size) { ssize_t wrote = TEMP_FAILURE_RETRY(write(wfd, buffer + written, size - written)); if (wrote == -1) { - ALOGE("error writing offset %lld: %s\n", (offset + written), strerror(errno)); + ALOGE("error writing offset %" PRId64 ": %s\n", + offset + static_cast(written), strerror(errno)); return -1; } written += wrote; @@ -200,10 +202,10 @@ static int produce_block_map(const char* path, const char* map_file, const char* return -1; } - ALOGI(" block size: %ld bytes\n", (long)sb.st_blksize); + ALOGI(" block size: %ld bytes\n", static_cast(sb.st_blksize)); int blocks = ((sb.st_size-1) / sb.st_blksize) + 1; - ALOGI(" file size: %lld bytes, %d blocks\n", (long long)sb.st_size, blocks); + ALOGI(" file size: %" PRId64 " bytes, %d blocks\n", sb.st_size, blocks); int range_alloc = 1; int range_used = 1; @@ -211,8 +213,8 @@ static int produce_block_map(const char* path, const char* map_file, const char* ranges[0] = -1; ranges[1] = -1; - fprintf(mapf.get(), "%s\n%lld %lu\n", - blk_dev, (long long)sb.st_size, (unsigned long)sb.st_blksize); + fprintf(mapf.get(), "%s\n%" PRId64 " %ld\n", + blk_dev, sb.st_size, static_cast(sb.st_blksize)); unsigned char* buffers[WINDOW_SIZE]; if (encrypted) { @@ -222,7 +224,6 @@ static int produce_block_map(const char* path, const char* map_file, const char* } int head_block = 0; int head = 0, tail = 0; - size_t pos = 0; int fd = open(path, O_RDONLY); unique_fd fd_holder(fd); @@ -242,6 +243,7 @@ static int produce_block_map(const char* path, const char* map_file, const char* } } + off64_t pos = 0; int last_progress = 0; while (pos < sb.st_size) { // Update the status file, progress must be between [0, 99]. @@ -261,7 +263,7 @@ static int produce_block_map(const char* path, const char* map_file, const char* add_block_to_ranges(&ranges, &range_alloc, &range_used, block); if (encrypted) { if (write_at_offset(buffers[head], sb.st_blksize, wfd, - (off64_t)sb.st_blksize * block) != 0) { + static_cast(sb.st_blksize) * block) != 0) { return -1; } } @@ -272,7 +274,7 @@ static int produce_block_map(const char* path, const char* map_file, const char* // read next block to tail if (encrypted) { size_t so_far = 0; - while (so_far < sb.st_blksize && pos < sb.st_size) { + while (so_far < static_cast(sb.st_blksize) && pos < sb.st_size) { ssize_t this_read = TEMP_FAILURE_RETRY(read(fd, buffers[tail] + so_far, sb.st_blksize - so_far)); if (this_read == -1) { @@ -301,7 +303,7 @@ static int produce_block_map(const char* path, const char* map_file, const char* add_block_to_ranges(&ranges, &range_alloc, &range_used, block); if (encrypted) { if (write_at_offset(buffers[head], sb.st_blksize, wfd, - (off64_t)sb.st_blksize * block) != 0) { + static_cast(sb.st_blksize) * block) != 0) { return -1; } } -- cgit v1.2.3