Whamcloud - gitweb
Fix Coverity unintentional integer overflow warnings
authorTheodore Ts'o <tytso@mit.edu>
Fri, 12 Aug 2022 02:03:08 +0000 (22:03 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 12 Aug 2022 02:03:08 +0000 (22:03 -0400)
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 <tytso@mit.edu>
misc/e2image.c
resize/main.c

index 0053b51..207c303 100644 (file)
@@ -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 */
index a1a1c79..b745c58 100644 (file)
@@ -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 -