mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
rust: Handle null pointer when creating slice
Starting with Rust 1.78 null assertions in the standard library are now checked when compiling in test/debug mode. Fixes: https://github.com/libguestfs/libguestfs/issues/145
This commit is contained in:
committed by
Richard W.M. Jones
parent
893c05fc40
commit
43946911c7
@@ -105,8 +105,16 @@ impl<'a> base::Handle<'a> {
|
||||
None => panic!("Failed to parse bitmask: {}", event),
|
||||
};
|
||||
let eh = EventHandle { eh: event_handle };
|
||||
let buf = unsafe { slice::from_raw_parts(buf as *const u8, buf_len) };
|
||||
let array = unsafe { slice::from_raw_parts(array, array_len) };
|
||||
let buf = if !buf.is_null() {
|
||||
unsafe { slice::from_raw_parts(buf as *const u8, buf_len) }
|
||||
} else {
|
||||
&[]
|
||||
};
|
||||
let array = if !array.is_null() {
|
||||
unsafe { slice::from_raw_parts(array, array_len) }
|
||||
} else {
|
||||
&[]
|
||||
};
|
||||
|
||||
let callback: &Box<dyn Fn(guestfs::Event, EventHandle, &[u8], &[u64])> =
|
||||
Box::leak(unsafe { Box::from_raw(opaque as *mut _) });
|
||||
|
||||
Reference in New Issue
Block a user