Skip to content

Commit a966107

Browse files
committed
fix(allocator): avoid number overflow in bump allocator init
1 parent 1ec5f7c commit a966107

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

kernel/src/allocator/bump.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ impl BumpAllocator {
2121

2222
pub unsafe fn init(&mut self, heap_start: usize, heap_size: usize) {
2323
self.heap_start = heap_start;
24-
self.heap_end = heap_start + heap_size;
24+
// Avoid overflow and thus prevent UB in Rust. If the sum exceeds usize::MAX, it saturates to the maximum.
25+
self.heap_end = heap_start.saturating_add(heap_size);
2526
self.next = heap_start;
2627
}
2728
}

0 commit comments

Comments
 (0)