File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -454,6 +454,8 @@ impl HoleList {
454
454
}
455
455
456
456
pub ( crate ) unsafe fn extend ( & mut self , by : usize ) {
457
+ assert ! ( !self . top. is_null( ) , "tried to extend an empty heap" ) ;
458
+
457
459
let top = self . top ;
458
460
459
461
let dead_space = top. align_offset ( align_of :: < Hole > ( ) ) ;
@@ -810,4 +812,10 @@ pub mod test {
810
812
// available size is too small to store a hole -> it should panic
811
813
unsafe { HoleList :: new ( heap_start. sub ( 1 ) , 2 * core:: mem:: size_of :: < usize > ( ) ) } ;
812
814
}
815
+
816
+ #[ test]
817
+ #[ should_panic]
818
+ fn extend_empty ( ) {
819
+ unsafe { HoleList :: empty ( ) . extend ( 16 ) } ;
820
+ }
813
821
}
Original file line number Diff line number Diff line change @@ -246,6 +246,8 @@ impl Heap {
246
246
/// at least `2 * size_of::<usize>`, keeping the amount a multiple of
247
247
/// `size_of::<usize>`.
248
248
///
249
+ /// Calling this method on an uninitialized Heap will panic.
250
+ ///
249
251
/// # Safety
250
252
///
251
253
/// The amount of data given in `by` MUST exist directly after the original
@@ -255,8 +257,6 @@ impl Heap {
255
257
/// Even if this operation doesn't increase the [usable size][`Self::size`]
256
258
/// by exactly `by` bytes, those bytes are still owned by the Heap for
257
259
/// later use.
258
- ///
259
- /// Calling this method on an uninitialized Heap is undefined behavior.
260
260
pub unsafe fn extend ( & mut self , by : usize ) {
261
261
self . holes . extend ( by) ;
262
262
}
You can’t perform that action at this time.
0 commit comments