From 5f4a6b42c0d7fd2937db9314f4752f90bcc40d9c Mon Sep 17 00:00:00 2001 From: Bo Chen Date: Fri, 16 Sep 2022 13:45:56 -0700 Subject: [PATCH] qcow: Fix wrong alignment calculation With the existing code, `round_up(7, 2)` would generate `6` which is obviously wrong. Also, following what's done for 'round_down()', the fixed code does not handle 'alignment == 0' explicitly. Signed-off-by: Bo Chen --- qcow/src/raw_file.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qcow/src/raw_file.rs b/qcow/src/raw_file.rs index 5b449e4b2..886f0481f 100644 --- a/qcow/src/raw_file.rs +++ b/qcow/src/raw_file.rs @@ -69,7 +69,7 @@ impl RawFile { fn round_up(&self, offset: u64) -> u64 { let align: u64 = self.alignment.try_into().unwrap(); - ((offset / (align + 1)) + 1) * align + ((offset + align - 1) / align) * align } fn round_down(&self, offset: u64) -> u64 {