File tree Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Original file line number Diff line number Diff line change 1+ #![ forbid( unsafe_op_in_unsafe_fn) ]  
12use  crate :: alloc:: { GlobalAlloc ,  Layout ,  System } ; 
23use  crate :: cmp; 
34use  crate :: ptr; 
@@ -46,14 +47,16 @@ pub unsafe fn realloc_fallback(
4647    old_layout :  Layout , 
4748    new_size :  usize , 
4849)  -> * mut  u8  { 
49-     // Docs for GlobalAlloc::realloc require this to be valid: 
50-     let  new_layout = Layout :: from_size_align_unchecked ( new_size,  old_layout. align ( ) ) ; 
50+     // SAFETY: Docs for GlobalAlloc::realloc require this to be valid 
51+     unsafe  { 
52+         let  new_layout = Layout :: from_size_align_unchecked ( new_size,  old_layout. align ( ) ) ; 
5153
52-     let  new_ptr = GlobalAlloc :: alloc ( alloc,  new_layout) ; 
53-     if  !new_ptr. is_null ( )  { 
54-         let  size = cmp:: min ( old_layout. size ( ) ,  new_size) ; 
55-         ptr:: copy_nonoverlapping ( ptr,  new_ptr,  size) ; 
56-         GlobalAlloc :: dealloc ( alloc,  ptr,  old_layout) ; 
54+         let  new_ptr = GlobalAlloc :: alloc ( alloc,  new_layout) ; 
55+         if  !new_ptr. is_null ( )  { 
56+             let  size = cmp:: min ( old_layout. size ( ) ,  new_size) ; 
57+             ptr:: copy_nonoverlapping ( ptr,  new_ptr,  size) ; 
58+             GlobalAlloc :: dealloc ( alloc,  ptr,  old_layout) ; 
59+         } 
60+         new_ptr
5761    } 
58-     new_ptr
5962} 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments