Skip to content

Commit 4512c11

Browse files
authored
Fixed heap creation when memory size is too small (#31)
1 parent 92a4fe1 commit 4512c11

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/lib.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,14 @@ impl Heap {
6161
/// anything else. This function is unsafe because it can cause undefined behavior if the
6262
/// given address is invalid.
6363
pub unsafe fn new(heap_bottom: usize, heap_size: usize) -> Heap {
64-
Heap {
65-
bottom: heap_bottom,
66-
size: heap_size,
67-
holes: HoleList::new(heap_bottom, heap_size),
64+
if heap_size < HoleList::min_size() {
65+
Self::empty()
66+
} else {
67+
Heap {
68+
bottom: heap_bottom,
69+
size: heap_size,
70+
holes: HoleList::new(heap_bottom, heap_size),
71+
}
6872
}
6973
}
7074

0 commit comments

Comments
 (0)