[libvirt PATCH] storage_file: Compute QCOW2 cluster size as ULL

Jiri Denemark posted 1 patch 2 years, 6 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/41b208bdbb57dda4d24796fc60a0f6028bcdee9b.1635175963.git.jdenemar@redhat.com
src/storage_file/storage_file_probe.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[libvirt PATCH] storage_file: Compute QCOW2 cluster size as ULL
Posted by Jiri Denemark 2 years, 6 months ago
While the QCOW2 cluster size is represented in only 4 bits in the QCOW2
header and thus 1 << cluster_size cannot overflow int,
qcow2GetClusterSize is supposed to return unsigned long long so we can
just compute the result as ULL rather than computing it as int and
promoting to unsigned long long.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/storage_file/storage_file_probe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/storage_file/storage_file_probe.c b/src/storage_file/storage_file_probe.c
index f5bb8b7dbb..dc438a5e5d 100644
--- a/src/storage_file/storage_file_probe.c
+++ b/src/storage_file/storage_file_probe.c
@@ -487,7 +487,7 @@ qcow2GetClusterSize(const char *buf,
     clusterBits = virReadBufInt32BE(buf + QCOWX_HDR_CLUSTER_BITS_OFFSET);
 
     if (clusterBits > 0)
-        return 1 << clusterBits;
+        return 1ULL << clusterBits;
 
     return 0;
 }
-- 
2.33.1

Re: [libvirt PATCH] storage_file: Compute QCOW2 cluster size as ULL
Posted by Pavel Hrdina 2 years, 6 months ago
On Mon, Oct 25, 2021 at 05:32:43PM +0200, Jiri Denemark wrote:
> While the QCOW2 cluster size is represented in only 4 bits in the QCOW2
> header and thus 1 << cluster_size cannot overflow int,
> qcow2GetClusterSize is supposed to return unsigned long long so we can
> just compute the result as ULL rather than computing it as int and
> promoting to unsigned long long.
> 
> Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
> ---
>  src/storage_file/storage_file_probe.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>