From af42d9b8191e15a84753305cbbb7746b77bb9f89 Mon Sep 17 00:00:00 2001 From: Simon Renblad Date: Tue, 28 Jan 2025 15:44:10 +0800 Subject: [PATCH] fix UB in UncachedSlice --- libcortex_a9/src/uncached.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libcortex_a9/src/uncached.rs b/libcortex_a9/src/uncached.rs index 1ff962c..2ebe19a 100644 --- a/libcortex_a9/src/uncached.rs +++ b/libcortex_a9/src/uncached.rs @@ -19,8 +19,8 @@ impl UncachedSlice { .max(L1_PAGE_SIZE); let layout = Layout::from_size_align(size, align)?; let ptr = unsafe { alloc::alloc::alloc(layout).cast::() }; + assert!(!ptr.is_null()); let start = ptr as usize; - assert_eq!(start & (L1_PAGE_SIZE - 1), 0); for page_start in (start..(start + size)).step_by(L1_PAGE_SIZE) { // non-shareable device @@ -33,9 +33,6 @@ impl UncachedSlice { } let slice = unsafe { core::slice::from_raw_parts_mut(ptr, len) }; - // verify size - assert!(unsafe { slice.get_unchecked(len) } as *const _ as usize <= start + size); - // initialize for e in slice.iter_mut() { *e = default(); }