mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-03-20 07:58:55 +00:00
virtio-devices: vsock: Address clippy issue
Issue from beta version of clippy: --> virtio-devices/src/vsock/csm/txbuf.rs:69:34 | 69 | Box::new(unsafe {mem::MaybeUninit::<[u8; Self::SIZE]>::uninit().assume_init()})); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[deny(clippy::uninit_assumed_init)]` on by default = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninit_assumed_init Fix backported Firecracker a8c9dffad439557081f3435a7819bf89b87870e7. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com> Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
c418074360
commit
a6da5f9e77
@ -3,7 +3,6 @@
|
||||
//
|
||||
|
||||
use std::io::Write;
|
||||
use std::mem;
|
||||
use std::num::Wrapping;
|
||||
|
||||
use super::defs;
|
||||
@ -15,7 +14,7 @@ use super::{Error, Result};
|
||||
///
|
||||
pub struct TxBuf {
|
||||
/// The actual u8 buffer - only allocated after the first push.
|
||||
data: Option<Box<[u8; Self::SIZE]>>,
|
||||
data: Option<Box<[u8]>>,
|
||||
/// Ring-buffer head offset - where new data is pushed to.
|
||||
head: Wrapping<u32>,
|
||||
/// Ring-buffer tail offset - where data is flushed from.
|
||||
@ -55,18 +54,9 @@ impl TxBuf {
|
||||
return Err(Error::TxBufFull);
|
||||
}
|
||||
|
||||
// We're using a closure here to return the boxed slice, instead of a value (i.e.
|
||||
// `get_or_insert_with()` instead of `get_or_insert()`), because we only want the box
|
||||
// created when `self.data` is None. If we were to use `get_or_insert(box)`, the box
|
||||
// argument would always get evaluated (which implies a heap allocation), even though
|
||||
// it would later be discarded (when `self.data.is_some()`). Apparently, clippy fails
|
||||
// to see this, and insists on issuing some warning.
|
||||
#[allow(clippy::redundant_closure)]
|
||||
let data = self.data.get_or_insert_with(||
|
||||
// Using uninitialized memory here is quite safe, since we never read from any
|
||||
// area of the buffer before writing to it. First we push, then we flush only
|
||||
// what had been previously pushed.
|
||||
Box::new(unsafe {mem::MaybeUninit::<[u8; Self::SIZE]>::uninit().assume_init()}));
|
||||
let data = self
|
||||
.data
|
||||
.get_or_insert_with(|| vec![0u8; Self::SIZE].into_boxed_slice());
|
||||
|
||||
// Buffer head, as an offset into the data slice.
|
||||
let head_ofs = self.head.0 as usize % Self::SIZE;
|
||||
|
Loading…
x
Reference in New Issue
Block a user