Skip to content

Commit 78e609c

Browse files
committed
Fix clippy warnings for hyperlight-guest
Signed-off-by: Mark Rossett <[email protected]>
1 parent 96f9c0c commit 78e609c

File tree

7 files changed

+25
-17
lines changed

7 files changed

+25
-17
lines changed

src/hyperlight_guest/src/guest_handle/handle.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ pub struct GuestHandle {
3030
peb: Option<*mut HyperlightPEB>,
3131
}
3232

33+
impl Default for GuestHandle {
34+
fn default() -> Self {
35+
Self::new()
36+
}
37+
}
38+
3339
impl GuestHandle {
3440
/// Creates a new uninitialized guest state.
3541
pub const fn new() -> Self {

src/hyperlight_guest/src/guest_handle/host_comm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ impl GuestHandle {
4141
let user_memory_region_size = unsafe { (*peb_ptr).init_data.size };
4242

4343
if num > user_memory_region_size {
44-
return Err(HyperlightGuestError::new(
44+
Err(HyperlightGuestError::new(
4545
ErrorCode::GuestError,
4646
format!(
4747
"Requested {} bytes from user memory, but only {} bytes are available",
4848
num, user_memory_region_size
4949
),
50-
));
50+
))
5151
} else {
5252
let user_memory_region_slice =
5353
unsafe { core::slice::from_raw_parts(user_memory_region_ptr, num as usize) };
@@ -142,7 +142,7 @@ impl GuestHandle {
142142
/// Write an error to the shared output data buffer.
143143
pub fn write_error(&self, error_code: ErrorCode, message: Option<&str>) {
144144
let guest_error: GuestError = GuestError::new(
145-
error_code.clone(),
145+
error_code,
146146
message.map_or("".to_string(), |m| m.to_string()),
147147
);
148148
let guest_error_buffer: Vec<u8> = (&guest_error)

src/hyperlight_guest_bin/src/exceptions/idtr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub(crate) unsafe fn load_idt() {
4949

5050
// Use &raw mut to get a mutable raw pointer, then dereference it
5151
// this is to avoid the clippy warning "shared reference to mutable static"
52+
#[allow(clippy::deref_addrof)]
5253
let idtr = &mut *(&raw mut IDTR);
5354
idtr.init(expected_base, idt_size as u16);
5455
idtr.load();

src/hyperlight_guest_bin/src/guest_function/call.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub(crate) fn call_guest_function(function_call: FunctionCall) -> Result<Vec<u8>
4242
// Find the function definition for the function call.
4343
// Use &raw const to get an immutable reference to the static HashMap
4444
// this is to avoid the clippy warning "shared reference to mutable static"
45+
#[allow(clippy::deref_addrof)]
4546
if let Some(registered_function_definition) =
4647
unsafe { (*(&raw const REGISTERED_GUEST_FUNCTIONS)).get(&function_call.function_name) }
4748
{
@@ -90,7 +91,7 @@ fn internal_dispatch_function() -> Result<()> {
9091
.expect("Function call deserialization failed");
9192

9293
let result_vec = call_guest_function(function_call).inspect_err(|e| {
93-
handle.write_error(e.kind.clone(), Some(e.message.as_str()));
94+
handle.write_error(e.kind, Some(e.message.as_str()));
9495
})?;
9596

9697
handle.push_shared_output_data(result_vec)

src/hyperlight_guest_bin/src/host_comm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub fn print_output_with_host_print(function_call: &FunctionCall) -> Result<Vec<
101101
pub unsafe extern "C" fn _putchar(c: c_char) {
102102
let handle = unsafe { GUEST_HANDLE };
103103
let char = c as u8;
104-
let mut message_buffer = unsafe { &mut MESSAGE_BUFFER };
104+
let message_buffer = unsafe { &mut MESSAGE_BUFFER };
105105

106106
// Extend buffer capacity if it's empty (like `with_capacity` in lazy_static).
107107
// TODO: replace above Vec::new() with Vec::with_capacity once it's stable in const contexts.
@@ -113,12 +113,12 @@ pub unsafe extern "C" fn _putchar(c: c_char) {
113113

114114
if message_buffer.len() == BUFFER_SIZE || char == b'\0' {
115115
let str = if char == b'\0' {
116-
CStr::from_bytes_until_nul(&message_buffer)
116+
CStr::from_bytes_until_nul(message_buffer)
117117
.expect("No null byte in buffer")
118118
.to_string_lossy()
119119
.into_owned()
120120
} else {
121-
String::from_utf8(mem::take(&mut message_buffer))
121+
String::from_utf8(mem::take(message_buffer))
122122
.expect("Failed to convert buffer to string")
123123
};
124124

src/hyperlight_guest_bin/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ pub extern "C" fn entrypoint(peb_address: u64, seed: u64, ops: u64, max_log_leve
103103
#[allow(static_mut_refs)]
104104
let peb_ptr = GUEST_HANDLE.peb().unwrap();
105105

106-
let srand_seed = ((peb_address << 8 ^ seed >> 4) >> 32) as u32;
106+
let srand_seed = (((peb_address << 8) ^ (seed >> 4)) >> 32) as u32;
107107

108108
// Set the seed for the random number generator for C code using rand;
109109
srand(srand_seed);

src/tests/rust_guests/witguest/Cargo.lock

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)