mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
virtio-devices: vsock: drop unsafe test len helper
The helper only needs to update the packet len field. Use write_slice() instead of rebuilding a mutable slice from a raw host pointer. Assisted-by: Codex:GPT-5 Signed-off-by: Dylan Reid <dgreid@fb.com>
This commit is contained in:
@@ -555,12 +555,11 @@ mod unit_tests {
|
||||
|
||||
fn set_pkt_len(len: u32, guest_desc: &GuestQDesc, mem: &GuestMemoryMmap) {
|
||||
let hdr_gpa = guest_desc.addr.get();
|
||||
let hdr_ptr =
|
||||
get_host_address_range(mem, GuestAddress(hdr_gpa), VSOCK_PKT_HDR_SIZE).unwrap();
|
||||
// SAFETY: The length is valid.
|
||||
let len_ptr = unsafe { hdr_ptr.add(HDROFF_LEN) };
|
||||
// SAFETY: The length is valid.
|
||||
LittleEndian::write_u32(unsafe { std::slice::from_raw_parts_mut(len_ptr, 4) }, len);
|
||||
mem.write_slice(
|
||||
&len.to_le_bytes(),
|
||||
GuestAddress(hdr_gpa + HDROFF_LEN as u64),
|
||||
)
|
||||
.expect("test packet header len field should be in guest memory");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user