Skip to content

Commit 188138f

Browse files
author
Jorge Aparicio
authored
Merge pull request #4 from japaric/size
fix the heap size calculation
2 parents 5563526 + bcfbec9 commit 188138f

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- The heap size is `end_addr` - `start_addr`. Previously, it was wrongly
13+
calculated as `end_addr - start_addr - 1`.
14+
1015
## [v0.2.0] - 2016-11-19
1116

1217
### Changed

src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@ static HEAP: Mutex<Heap> = Mutex::new(Heap::empty());
7070
/// - The heap grows "upwards", towards larger addresses. Thus `end_addr` must
7171
/// be larger than `start_addr`
7272
///
73-
/// - The size of the heap will actually be
74-
/// `(end_addr as usize) - (start_addr as usize) + 1` because the allocator
75-
/// won't use the byte at `end_addr`.
73+
/// - The size of the heap is `(end_addr as usize) - (start_addr as usize)`. The
74+
/// allocator won't use the byte at `end_addr`.
7675
///
7776
/// # Unsafety
7877
///
@@ -83,7 +82,7 @@ static HEAP: Mutex<Heap> = Mutex::new(Heap::empty());
8382
pub unsafe fn init(start_addr: *mut usize, end_addr: *mut usize) {
8483
let start = start_addr as usize;
8584
let end = end_addr as usize;
86-
let size = (end - start) - 1;
85+
let size = end - start;
8786
HEAP.lock(|heap| heap.init(start, size));
8887
}
8988

0 commit comments

Comments
 (0)