From 6b3edcd191c20b3fb108f0d7564aaa930035d0ab Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Thu, 11 Aug 2022 22:03:08 -0400 Subject: [PATCH] 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 --- misc/e2image.c | 2 +- resize/main.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 - -- 1.8.3.1