mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-28 08:17:37 +00:00
rust-agent: Remove unused code that has undefined behavior
Some functions have undefined behavior and are not actually used. This addresses the following warning: warning: the type `oci::User` does not permit zero-initialization --> rustjail/src/lib.rs:99:18 | 99 | unsafe { MaybeUninit::zeroed().assume_init() } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | this code causes undefined behavior when executed | help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done | = note: `#[warn(invalid_value)]` on by default note: `std::ptr::Unique<u32>` must be non-null (in this struct field) warning: the type `protocols::oci::Process` does not permit zero-initialization --> rustjail/src/lib.rs:146:14 | 146 | unsafe { MaybeUninit::zeroed().assume_init() } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | this code causes undefined behavior when executed | help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done | note: `std::ptr::Unique<std::string::String>` must be non-null (in this struct field) Fixes: #750 Signed-off-by: Christophe de Dinechin <dinechin@redhat.com>
This commit is contained in:
parent
86bc151787
commit
19cb657299
@ -69,7 +69,6 @@ use protocols::oci::{
|
||||
Root as grpcRoot, Spec as grpcSpec,
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
use std::mem::MaybeUninit;
|
||||
|
||||
pub fn process_grpc_to_oci(p: &grpcProcess) -> ociProcess {
|
||||
let console_size = if p.ConsoleSize.is_some() {
|
||||
@ -91,7 +90,12 @@ pub fn process_grpc_to_oci(p: &grpcProcess) -> ociProcess {
|
||||
username: u.Username.clone(),
|
||||
}
|
||||
} else {
|
||||
unsafe { MaybeUninit::zeroed().assume_init() }
|
||||
ociUser {
|
||||
uid: 0,
|
||||
gid: 0,
|
||||
additional_gids: vec![],
|
||||
username: String::from(""),
|
||||
}
|
||||
};
|
||||
|
||||
let capabilities = if p.Capabilities.is_some() {
|
||||
@ -136,11 +140,6 @@ pub fn process_grpc_to_oci(p: &grpcProcess) -> ociProcess {
|
||||
}
|
||||
}
|
||||
|
||||
fn process_oci_to_grpc(_p: ociProcess) -> grpcProcess {
|
||||
// dont implement it for now
|
||||
unsafe { MaybeUninit::zeroed().assume_init() }
|
||||
}
|
||||
|
||||
fn root_grpc_to_oci(root: &grpcRoot) -> ociRoot {
|
||||
ociRoot {
|
||||
path: root.Path.clone(),
|
||||
@ -148,10 +147,6 @@ fn root_grpc_to_oci(root: &grpcRoot) -> ociRoot {
|
||||
}
|
||||
}
|
||||
|
||||
fn root_oci_to_grpc(_root: &ociRoot) -> grpcRoot {
|
||||
unsafe { MaybeUninit::zeroed().assume_init() }
|
||||
}
|
||||
|
||||
fn mount_grpc_to_oci(m: &grpcMount) -> ociMount {
|
||||
ociMount {
|
||||
destination: m.destination.clone(),
|
||||
@ -161,10 +156,6 @@ fn mount_grpc_to_oci(m: &grpcMount) -> ociMount {
|
||||
}
|
||||
}
|
||||
|
||||
fn mount_oci_to_grpc(_m: &ociMount) -> grpcMount {
|
||||
unsafe { MaybeUninit::zeroed().assume_init() }
|
||||
}
|
||||
|
||||
use oci::Hook as ociHook;
|
||||
use protocols::oci::Hook as grpcHook;
|
||||
|
||||
@ -195,10 +186,6 @@ fn hooks_grpc_to_oci(h: &grpcHooks) -> ociHooks {
|
||||
}
|
||||
}
|
||||
|
||||
fn hooks_oci_to_grpc(_h: &ociHooks) -> grpcHooks {
|
||||
unsafe { MaybeUninit::zeroed().assume_init() }
|
||||
}
|
||||
|
||||
use oci::{
|
||||
LinuxDevice as ociLinuxDevice, LinuxIDMapping as ociLinuxIDMapping,
|
||||
LinuxIntelRdt as ociLinuxIntelRdt, LinuxNamespace as ociLinuxNamespace,
|
||||
@ -565,10 +552,6 @@ pub fn grpc_to_oci(grpc: &grpcSpec) -> ociSpec {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn oci_to_grpc(_oci: &ociSpec) -> grpcSpec {
|
||||
unsafe { MaybeUninit::zeroed().assume_init() }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user