From 0cca3ae90c75fdb9f7e75d261d87f792ceb51453 Mon Sep 17 00:00:00 2001 From: Calvin Lee Date: Thu, 22 Sep 2016 12:25:59 -0600 Subject: [PATCH] Fixes #220: BumpAllocator overflow I also fixed a spelling error and replaced a tab with a space in the blog post where `allocate()` was created. (cherry picked from commit 54e02fd6b5f1632ee1331d301d63ccd3fb8063cd) (cherry picked from commit 3a2f0b33297164ebbfab92ee76881b6c06c4914d) --- libs/bump_allocator/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/bump_allocator/src/lib.rs b/libs/bump_allocator/src/lib.rs index 3868aecb..90ffe374 100644 --- a/libs/bump_allocator/src/lib.rs +++ b/libs/bump_allocator/src/lib.rs @@ -35,7 +35,7 @@ impl BumpAllocator { /// Allocates a block of memory with the given size and alignment. fn allocate(&mut self, size: usize, align: usize) -> Option<*mut u8> { let alloc_start = align_up(self.next, align); - let alloc_end = alloc_start + size; + let alloc_end = alloc_start.saturating_add(size); if alloc_end <= self.heap_start + self.heap_size { self.next = alloc_end;