We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1ec5f7c commit a966107Copy full SHA for a966107
kernel/src/allocator/bump.rs
@@ -21,7 +21,8 @@ impl BumpAllocator {
21
22
pub unsafe fn init(&mut self, heap_start: usize, heap_size: usize) {
23
self.heap_start = heap_start;
24
- self.heap_end = heap_start + heap_size;
+ // 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);
26
self.next = heap_start;
27
}
28
0 commit comments