File tree 1 file changed +11
-8
lines changed
1 file changed +11
-8
lines changed Original file line number Diff line number Diff line change
1
+ #![ forbid( unsafe_op_in_unsafe_fn) ]
1
2
use crate :: alloc:: { GlobalAlloc , Layout , System } ;
2
3
use crate :: cmp;
3
4
use crate :: ptr;
@@ -46,14 +47,16 @@ pub unsafe fn realloc_fallback(
46
47
old_layout : Layout ,
47
48
new_size : usize ,
48
49
) -> * 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 ( ) ) ;
51
53
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
57
61
}
58
- new_ptr
59
62
}
You can’t perform that action at this time.
0 commit comments