Skip to content

Commit ff27e01

Browse files
committed
Change get_header to use raw pointers
1 parent ef8baea commit ff27e01

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

library/std/src/sys/windows/alloc.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![deny(unsafe_op_in_unsafe_fn)]
22

33
use crate::alloc::{GlobalAlloc, Layout, System};
4+
use crate::ptr;
45
use crate::sys::c;
56
use crate::sys_common::alloc::{realloc_fallback, MIN_ALIGN};
67

@@ -10,7 +11,7 @@ struct Header(*mut u8);
1011
/// # Safety
1112
///
1213
/// There must be a `Header` at `ptr.offset(-1)`.
13-
unsafe fn get_header<'a>(ptr: *mut u8) -> &'a mut Header {
14+
unsafe fn get_header<'a>(ptr: *mut u8) -> *mut Header {
1415
// SAFETY: the safety contract must be upheld by the caller
1516
unsafe { &mut *(ptr as *mut Header).offset(-1) }
1617
}
@@ -22,7 +23,7 @@ unsafe fn align_ptr(ptr: *mut u8, align: usize) -> *mut u8 {
2223
// SAFETY: the safety contract must be upheld by the caller
2324
unsafe {
2425
let aligned = ptr.add(align - (ptr as usize & (align - 1)));
25-
*get_header(aligned) = Header(ptr);
26+
ptr::write(get_header(aligned), Header(ptr));
2627
aligned
2728
}
2829
}
@@ -74,7 +75,7 @@ unsafe impl GlobalAlloc for System {
7475
c::HeapFree(c::GetProcessHeap(), 0, ptr as c::LPVOID)
7576
} else {
7677
let header = get_header(ptr);
77-
c::HeapFree(c::GetProcessHeap(), 0, header.0 as c::LPVOID)
78+
c::HeapFree(c::GetProcessHeap(), 0, (*header).0 as c::LPVOID)
7879
}
7980
};
8081
// SAFETY: `c::GetLastError()` cannot fail

0 commit comments

Comments
 (0)