Make 'image_offset' unsigned
Since 'image_offset' represents a file offset, it is always unsigned. Make
its type unsigned to prevent that a cast has to be introduced in the next
patch when assigning an image offset to the 'lo_offset' member.
Bug: 194450129
Test: Built Android images and installed these on an Android phone.
Change-Id: I884d91647669560148c5f62cef68633b1a8c7a7d
Signed-off-by: Bart Van Assche <bvanassche@google.com>
diff --git a/apexd/apex_file.cpp b/apexd/apex_file.cpp
index 152e580..91be4a2 100644
--- a/apexd/apex_file.cpp
+++ b/apexd/apex_file.cpp
@@ -62,7 +62,7 @@
constexpr const FsMagic kFsType[] = {{"f2fs", 1024, 4, "\x10\x20\xf5\xf2"},
{"ext4", 1024 + 0x38, 2, "\123\357"}};
-Result<std::string> RetrieveFsType(borrowed_fd fd, int32_t image_offset) {
+Result<std::string> RetrieveFsType(borrowed_fd fd, uint32_t image_offset) {
for (const auto& fs : kFsType) {
char buf[fs.len];
if (!ReadFullyAtOffset(fd, buf, fs.len, image_offset + fs.offset)) {
@@ -78,7 +78,7 @@
} // namespace
Result<ApexFile> ApexFile::Open(const std::string& path) {
- std::optional<int32_t> image_offset;
+ std::optional<uint32_t> image_offset;
std::optional<size_t> image_size;
std::string manifest_content;
std::string pubkey;
diff --git a/apexd/apex_file.h b/apexd/apex_file.h
index 625e8b0..56077bb 100644
--- a/apexd/apex_file.h
+++ b/apexd/apex_file.h
@@ -48,7 +48,9 @@
ApexFile& operator=(ApexFile&&) = default;
const std::string& GetPath() const { return apex_path_; }
- const std::optional<int32_t>& GetImageOffset() const { return image_offset_; }
+ const std::optional<uint32_t>& GetImageOffset() const {
+ return image_offset_;
+ }
const std::optional<size_t>& GetImageSize() const { return image_size_; }
const ::apex::proto::ApexManifest& GetManifest() const { return manifest_; }
const std::string& GetBundledPublicKey() const { return apex_pubkey_; }
@@ -60,7 +62,7 @@
private:
ApexFile(const std::string& apex_path,
- const std::optional<int32_t>& image_offset,
+ const std::optional<uint32_t>& image_offset,
const std::optional<size_t>& image_size,
::apex::proto::ApexManifest manifest, const std::string& apex_pubkey,
const std::optional<std::string>& fs_type, bool is_compressed)
@@ -73,7 +75,7 @@
is_compressed_(is_compressed) {}
std::string apex_path_;
- std::optional<int32_t> image_offset_;
+ std::optional<uint32_t> image_offset_;
std::optional<size_t> image_size_;
::apex::proto::ApexManifest manifest_;
std::string apex_pubkey_;
diff --git a/apexd/apex_file_test.cpp b/apexd/apex_file_test.cpp
index e50bca5..d42af09 100644
--- a/apexd/apex_file_test.cpp
+++ b/apexd/apex_file_test.cpp
@@ -56,7 +56,7 @@
Result<ApexFile> apex_file = ApexFile::Open(file_path);
ASSERT_TRUE(apex_file.ok());
- int32_t zip_image_offset;
+ uint32_t zip_image_offset;
size_t zip_image_size;
{
ZipArchiveHandle handle;
@@ -70,7 +70,7 @@
ASSERT_EQ(0, rc);
zip_image_offset = entry.offset;
- EXPECT_EQ(zip_image_offset % 4096, 0);
+ EXPECT_EQ(zip_image_offset % 4096, 0U);
zip_image_size = entry.uncompressed_length;
EXPECT_EQ(zip_image_size, entry.compressed_length);
}
diff --git a/apexd/apexd_loop.cpp b/apexd/apexd_loop.cpp
index fc2b91c..f096cff 100644
--- a/apexd/apexd_loop.cpp
+++ b/apexd/apexd_loop.cpp
@@ -150,7 +150,7 @@
}
Result<void> ConfigureLoopDevice(const int device_fd, const std::string& target,
- const int32_t image_offset,
+ const uint32_t image_offset,
const size_t image_size) {
static bool use_loop_configure;
static std::once_flag once_flag;
@@ -292,7 +292,7 @@
}
Result<LoopbackDeviceUniqueFd> CreateLoopDevice(const std::string& target,
- const int32_t image_offset,
+ const uint32_t image_offset,
const size_t image_size) {
ATRACE_NAME("CreateLoopDevice");
unique_fd ctl_fd(open("/dev/loop-control", O_RDWR | O_CLOEXEC));
diff --git a/apexd/apexd_loop.h b/apexd/apexd_loop.h
index 4c44077..7262865 100644
--- a/apexd/apexd_loop.h
+++ b/apexd/apexd_loop.h
@@ -62,7 +62,7 @@
android::base::Result<void> PreAllocateLoopDevices(size_t num);
android::base::Result<LoopbackDeviceUniqueFd> CreateLoopDevice(
- const std::string& target, const int32_t image_offset,
+ const std::string& target, const uint32_t image_offset,
const size_t image_size);
using DestroyLoopFn =