diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d5e360..ac05ea7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Fixed + +- The heap size is `end_addr` - `start_addr`. Previously, it was wrongly + calculated as `end_addr - start_addr - 1`. + ## [v0.2.0] - 2016-11-19 ### Changed diff --git a/src/lib.rs b/src/lib.rs index 8d2430d..4791b2c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -70,9 +70,8 @@ static HEAP: Mutex = Mutex::new(Heap::empty()); /// - The heap grows "upwards", towards larger addresses. Thus `end_addr` must /// be larger than `start_addr` /// -/// - The size of the heap will actually be -/// `(end_addr as usize) - (start_addr as usize) + 1` because the allocator -/// won't use the byte at `end_addr`. +/// - The size of the heap is `(end_addr as usize) - (start_addr as usize)`. The +/// allocator won't use the byte at `end_addr`. /// /// # Unsafety /// @@ -83,7 +82,7 @@ static HEAP: Mutex = Mutex::new(Heap::empty()); pub unsafe fn init(start_addr: *mut usize, end_addr: *mut usize) { let start = start_addr as usize; let end = end_addr as usize; - let size = (end - start) - 1; + let size = end - start; HEAP.lock(|heap| heap.init(start, size)); }