mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-02 06:41:14 +00:00
Fix crash when an allocation fails
This commit is contained in:
parent
55a291bcbc
commit
cbfd2637cf
1 changed files with 7 additions and 0 deletions
|
@ -52,6 +52,7 @@ unsafe fn drop_inner<T>(inner: NonNull<SharedArrayInner<T>>) {
|
|||
/// Allocate the memory for the SharedArray with the given capacity. Return the inner with size and refcount set to 1
|
||||
fn alloc_with_capacity<T>(capacity: usize) -> NonNull<SharedArrayInner<T>> {
|
||||
let ptr = unsafe { alloc::alloc(compute_inner_layout::<T>(capacity)) };
|
||||
assert!(!ptr.is_null(), "allocation of {:?} bytes failled", capacity);
|
||||
unsafe {
|
||||
core::ptr::write(
|
||||
ptr as *mut SharedArrayHeader,
|
||||
|
@ -444,6 +445,12 @@ fn push_test() {
|
|||
assert_eq!(y.as_slice(), &[1, 2, 3]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn invalid_capacity_test() {
|
||||
let _: SharedArray<u8> = SharedArray::with_capacity(usize::MAX / 2 - 1000);
|
||||
}
|
||||
|
||||
pub(crate) mod ffi {
|
||||
use super::*;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue