Skip to content

Commit 99bd76c

Browse files
authored
virt_mshv: Fix u128 conversion (#1856)
The parts were swapped. Found by GPT-5.
1 parent e4c2f44 commit 99bd76c

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

vmm_core/virt_mshv/src/lib.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,8 +1321,21 @@ fn hvu128_to_u128(r: &hv_u128) -> u128 {
13211321

13221322
fn u128_to_hvu128(value: u128) -> hv_u128 {
13231323
hv_u128 {
1324-
high_part: (value & (u64::MAX as u128)) as u64,
1325-
low_part: (value >> 64) as u64,
1324+
high_part: (value >> 64) as u64,
1325+
low_part: (value & (u64::MAX as u128)) as u64,
1326+
}
1327+
}
1328+
1329+
#[cfg(test)]
1330+
mod tests {
1331+
use super::*;
1332+
1333+
#[test]
1334+
fn u128_roundtrip() {
1335+
let original = 0x0123_4567_89ab_cdef_fedc_ba98_7654_3210;
1336+
let hv = u128_to_hvu128(original);
1337+
let roundtrip = hvu128_to_u128(&hv);
1338+
assert_eq!(roundtrip, original);
13261339
}
13271340
}
13281341

0 commit comments

Comments
 (0)