File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change 11#![ feature( const_fn) ]
2- #![ cfg_attr( feature = "alloc_ref" , feature( allocator_api) ) ]
2+ #![ cfg_attr( feature = "alloc_ref" , feature( allocator_api, alloc_layout_extra ) ) ]
33#![ no_std]
44
55#[ cfg( test) ]
@@ -133,15 +133,20 @@ impl Heap {
133133
134134#[ cfg( feature = "alloc_ref" ) ]
135135unsafe impl AllocRef for Heap {
136- unsafe fn alloc ( & mut self , layout : Layout ) -> Result < ( NonNull < u8 > , usize ) , AllocErr > {
136+ fn alloc ( & mut self , layout : Layout ) -> Result < ( NonNull < u8 > , usize ) , AllocErr > {
137+ if layout. size ( ) == 0 {
138+ return Ok ( ( layout. dangling ( ) , 0 ) ) ;
139+ }
137140 match self . allocate_first_fit ( layout) {
138141 Ok ( ptr) => Ok ( ( ptr, layout. size ( ) ) ) ,
139142 Err ( ( ) ) => Err ( AllocErr ) ,
140143 }
141144 }
142145
143146 unsafe fn dealloc ( & mut self , ptr : NonNull < u8 > , layout : Layout ) {
144- self . deallocate ( ptr, layout)
147+ if layout. size ( ) != 0 {
148+ self . deallocate ( ptr, layout) ;
149+ }
145150 }
146151}
147152
You can’t perform that action at this time.
0 commit comments