File tree 1 file changed +8
-3
lines changed
1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change 1
1
#![ feature( const_fn) ]
2
- #![ cfg_attr( feature = "alloc_ref" , feature( allocator_api) ) ]
2
+ #![ cfg_attr( feature = "alloc_ref" , feature( allocator_api, alloc_layout_extra ) ) ]
3
3
#![ no_std]
4
4
5
5
#[ cfg( test) ]
@@ -133,15 +133,20 @@ impl Heap {
133
133
134
134
#[ cfg( feature = "alloc_ref" ) ]
135
135
unsafe 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
+ }
137
140
match self . allocate_first_fit ( layout) {
138
141
Ok ( ptr) => Ok ( ( ptr, layout. size ( ) ) ) ,
139
142
Err ( ( ) ) => Err ( AllocErr ) ,
140
143
}
141
144
}
142
145
143
146
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
+ }
145
150
}
146
151
}
147
152
You can’t perform that action at this time.
0 commit comments