Loading libs/nativewindow/rust/src/lib.rs +5 −0 Original line number Original line Diff line number Diff line Loading @@ -199,6 +199,7 @@ mod ahardwarebuffer_tests { #[test] #[test] #[should_panic] #[should_panic] fn take_from_raw_panics_on_null() { fn take_from_raw_panics_on_null() { // SAFETY: Passing a null pointer is safe, it should just panic. unsafe { AHardwareBuffer::take_from_raw(ptr::null_mut()) }; unsafe { AHardwareBuffer::take_from_raw(ptr::null_mut()) }; } } Loading @@ -216,9 +217,13 @@ mod ahardwarebuffer_tests { }; }; let mut raw_buffer_ptr = ptr::null_mut(); let mut raw_buffer_ptr = ptr::null_mut(); // SAFETY: The pointers are valid because they come from references, and // `AHardwareBuffer_allocate` doesn't retain them after it returns. let status = unsafe { ffi::AHardwareBuffer_allocate(&buffer_desc, &mut raw_buffer_ptr) }; let status = unsafe { ffi::AHardwareBuffer_allocate(&buffer_desc, &mut raw_buffer_ptr) }; assert_eq!(status, 0); assert_eq!(status, 0); // SAFETY: The pointer must be valid because it was just allocated successfully, and we // don't use it after calling this. let buffer = unsafe { AHardwareBuffer::take_from_raw(raw_buffer_ptr as *mut c_void) }; let buffer = unsafe { AHardwareBuffer::take_from_raw(raw_buffer_ptr as *mut c_void) }; assert_eq!(buffer.width(), 1024); assert_eq!(buffer.width(), 1024); } } Loading Loading
libs/nativewindow/rust/src/lib.rs +5 −0 Original line number Original line Diff line number Diff line Loading @@ -199,6 +199,7 @@ mod ahardwarebuffer_tests { #[test] #[test] #[should_panic] #[should_panic] fn take_from_raw_panics_on_null() { fn take_from_raw_panics_on_null() { // SAFETY: Passing a null pointer is safe, it should just panic. unsafe { AHardwareBuffer::take_from_raw(ptr::null_mut()) }; unsafe { AHardwareBuffer::take_from_raw(ptr::null_mut()) }; } } Loading @@ -216,9 +217,13 @@ mod ahardwarebuffer_tests { }; }; let mut raw_buffer_ptr = ptr::null_mut(); let mut raw_buffer_ptr = ptr::null_mut(); // SAFETY: The pointers are valid because they come from references, and // `AHardwareBuffer_allocate` doesn't retain them after it returns. let status = unsafe { ffi::AHardwareBuffer_allocate(&buffer_desc, &mut raw_buffer_ptr) }; let status = unsafe { ffi::AHardwareBuffer_allocate(&buffer_desc, &mut raw_buffer_ptr) }; assert_eq!(status, 0); assert_eq!(status, 0); // SAFETY: The pointer must be valid because it was just allocated successfully, and we // don't use it after calling this. let buffer = unsafe { AHardwareBuffer::take_from_raw(raw_buffer_ptr as *mut c_void) }; let buffer = unsafe { AHardwareBuffer::take_from_raw(raw_buffer_ptr as *mut c_void) }; assert_eq!(buffer.width(), 1024); assert_eq!(buffer.width(), 1024); } } Loading