Skip to content

Commit 4023c90

Browse files
committed
Unwrap checked pointer, and error handling for null pointers
1 parent 07abebb commit 4023c90

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

renderer/src/lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,20 @@ pub fn create_surface(
182182
let (raw_window_handle, raw_display_handle) = {
183183
use raw_window_handle::{WaylandDisplayHandle, WaylandWindowHandle};
184184

185-
let window_handle_ptr = unsafe { NonNull::new_unchecked(window_handle as *mut c_void) };
185+
if window_handle == 0 {
186+
return Err(error::ProcessingError::HandleError(
187+
HandleError::Unavailable,
188+
));
189+
}
190+
let window_handle_ptr = NonNull::new(window_handle as *mut c_void).unwrap();
186191
let window = WaylandWindowHandle::new(window_handle_ptr);
187192

188-
let display_handle_ptr = unsafe { NonNull::new_unchecked(display_handle as *mut c_void) };
193+
if display_handle == 0 {
194+
return Err(error::ProcessingError::HandleError(
195+
HandleError::Unavailable,
196+
));
197+
}
198+
let display_handle_ptr = NonNull::new(display_handle as *mut c_void).unwrap();
189199
let display = WaylandDisplayHandle::new(display_handle_ptr);
190200

191201
(

0 commit comments

Comments
 (0)