From: Theodore Ts'o Date: Fri, 12 Aug 2022 02:03:08 +0000 (-0400) Subject: Fix Coverity unintentional integer overflow warnings X-Git-Tag: v1.46.6-rc1~25 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=6b3edcd191c20b3fb108f0d7564aaa930035d0ab;p=tools%2Fe2fsprogs.git Fix Coverity unintentional integer overflow warnings Neither of these two warnings can actually happen (other limits will be hit first), but widening the integer to a 64-bit unsigned integer is an cheap and effective way to silence the Coverity warnings. Addresses-Coverity-Bug: 1500760 Addresses-Coverity-Bug: 1507886 Signed-off-by: Theodore Ts'o --- diff --git a/misc/e2image.c b/misc/e2image.c index 0053b51..207c303 100644 --- a/misc/e2image.c +++ b/misc/e2image.c @@ -943,7 +943,7 @@ static errcode_t initialize_qcow2_image(int fd, ext2_filsys fs, header->refcount_table_clusters = ext2fs_cpu_to_be32(image->refcount.refcount_table_clusters); offset += image->cluster_size; - offset += image->refcount.refcount_table_clusters << + offset += (blk64_t) image->refcount.refcount_table_clusters << image->cluster_bits; /* Make space for L2 tables */ diff --git a/resize/main.c b/resize/main.c index a1a1c79..b745c58 100644 --- a/resize/main.c +++ b/resize/main.c @@ -544,7 +544,7 @@ int main (int argc, char ** argv) /* If using cluster allocations, trim down to a cluster boundary */ if (ext2fs_has_feature_bigalloc(fs->super)) { - new_size &= ~((blk64_t)(1 << fs->cluster_ratio_bits) - 1); + new_size &= ~((blk64_t)(1ULL << fs->cluster_ratio_bits) - 1); } new_group_desc_count = ext2fs_div64_ceil(new_size -