dynamic-partitions: testlib: Fix overflow coverity issue 03/308403/1
authorJaehoon Chung <jh80.chung@samsung.com>
Mon, 25 Mar 2024 02:07:58 +0000 (11:07 +0900)
committerJaehoon Chung <jh80.chung@samsung.com>
Mon, 25 Mar 2024 02:11:31 +0000 (11:11 +0900)
It should be overflow according to multiply number_of_parts by
PART_SIZE_B. The  type of  number_of_parts is 'int'. To prevent
incorrect operation, cast a proper type.

Change-Id: I8fd44cc7622b25631f49f7df670a7a5bf435997e
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
src/dynamic-partitions/testlib/metadataio.cpp

index 58c7ac9..1a05dc5 100644 (file)
@@ -43,7 +43,7 @@ void addPartitions(android::fs_mgr::LpMetadata &metadata, int number_of_groups,
 }
 
 std::unique_ptr<android::fs_mgr::LpMetadata> addPartitions(int number_of_groups, int number_of_parts) {
-    uint64_t group_size = number_of_parts * PART_SIZE_B;
+    uint64_t group_size = uint64_t(number_of_parts) * PART_SIZE_B;
     uint64_t super_size = ALIGNMENT + number_of_groups * group_size;
 
     auto builder = android::fs_mgr::MetadataBuilder::New(super_size, METADATA_SIZE, number_of_groups, ALIGNMENT);