From 12b90553d784b9d4ddd1b48300af6345bdf1085f Mon Sep 17 00:00:00 2001 From: Tianjie Xu Date: Tue, 7 Mar 2017 14:44:14 -0800 Subject: More cleanup to imgdiff & imgpatch Also remove the utils in applypatch and replace them with the corresponding libbase functions. Test: recovery tests pass. Change-Id: I77254c141bd3e7d3d6894c23b60e866009516f81 --- applypatch/imgpatch.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'applypatch/imgpatch.cpp') diff --git a/applypatch/imgpatch.cpp b/applypatch/imgpatch.cpp index 8f4a2a42b..adcc61fd6 100644 --- a/applypatch/imgpatch.cpp +++ b/applypatch/imgpatch.cpp @@ -31,10 +31,17 @@ #include #include +#include #include #include -#include "utils.h" +static inline int64_t Read8(const void *address) { + return android::base::get_unaligned(address); +} + +static inline int32_t Read4(const void *address) { + return android::base::get_unaligned(address); +} int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size, const unsigned char* patch_data, ssize_t patch_size, @@ -86,9 +93,9 @@ int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size, const Value return -1; } - size_t src_start = Read8(normal_header); - size_t src_len = Read8(normal_header + 8); - size_t patch_offset = Read8(normal_header + 16); + size_t src_start = static_cast(Read8(normal_header)); + size_t src_len = static_cast(Read8(normal_header + 8)); + size_t patch_offset = static_cast(Read8(normal_header + 16)); if (src_start + src_len > static_cast(old_size)) { printf("source data too short\n"); @@ -125,11 +132,11 @@ int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size, const Value return -1; } - size_t src_start = Read8(deflate_header); - size_t src_len = Read8(deflate_header + 8); - size_t patch_offset = Read8(deflate_header + 16); - size_t expanded_len = Read8(deflate_header + 24); - size_t target_len = Read8(deflate_header + 32); + size_t src_start = static_cast(Read8(deflate_header)); + size_t src_len = static_cast(Read8(deflate_header + 8)); + size_t patch_offset = static_cast(Read8(deflate_header + 16)); + size_t expanded_len = static_cast(Read8(deflate_header + 24)); + size_t target_len = static_cast(Read8(deflate_header + 32)); int level = Read4(deflate_header + 40); int method = Read4(deflate_header + 44); int windowBits = Read4(deflate_header + 48); -- cgit v1.2.3