Skip to content

fix the heap size calculation #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ static HEAP: Mutex<Heap> = 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
///
Expand All @@ -83,7 +82,7 @@ static HEAP: Mutex<Heap> = 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));
}

Expand Down