Skip to content

Commit

Permalink
iOS/tvOS/watchOS: Fix alloc w. large alignment on older versions
Browse files Browse the repository at this point in the history
Tested on an old MacBook and the iOS simulator.
  • Loading branch information
madsmtm committed May 6, 2024
1 parent aa606bb commit 53bd38b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion library/std/src/sys/pal/unix/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ unsafe impl GlobalAlloc for System {
if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() {
libc::malloc(layout.size()) as *mut u8
} else {
#[cfg(target_os = "macos")]
// `posix_memalign` returns a non-aligned value if supplied a very
// large alignment on older versions of Apple's platforms (unknown
// exactly which version range, but the issue is definitely
// present in macOS 10.14 and iOS 13.3).
//
// <https://github.com/rust-lang/rust/issues/30170>
#[cfg(target_vendor = "apple")]
{
if layout.align() > (1 << 31) {
return ptr::null_mut();
Expand Down

0 comments on commit 53bd38b

Please sign in to comment.