mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-17 14:57:49 +00:00
Don't panic on overflow in allocator; return null pointer instead (#738)
This commit is contained in:
committed by
GitHub
parent
9fb6c1d0bd
commit
3a6d3153a4
@@ -86,7 +86,7 @@ impl LinkedListAllocator {
|
||||
/// Returns the allocation start address on success.
|
||||
fn alloc_from_region(region: &ListNode, size: usize, align: usize) -> Result<usize, ()> {
|
||||
let alloc_start = align_up(region.start_addr(), align);
|
||||
let alloc_end = alloc_start.checked_add(size).expect("overflow");
|
||||
let alloc_end = alloc_start.checked_add(size).ok_or(())?;
|
||||
|
||||
if alloc_end > region.end_addr() {
|
||||
// region too small
|
||||
|
||||
Reference in New Issue
Block a user