Skip to content

Commit f6b46f5

Browse files
committed
Added macos guards
1 parent 4008c0a commit f6b46f5

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
extern crate libmimalloc_sys as ffi;
2828

2929
use core::alloc::{GlobalAlloc, Layout};
30+
use core::ptr;
3031
use libc::c_void;
3132
use ffi::*;
3233

@@ -68,6 +69,13 @@ unsafe impl GlobalAlloc for MiMalloc {
6869
if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() {
6970
mi_malloc(layout.size()) as *mut u8
7071
} else {
72+
#[cfg(target_os = "macos")]
73+
{
74+
if layout.align() > (1 << 31) {
75+
return ptr::null_mut()
76+
}
77+
}
78+
7179
mi_malloc_aligned(layout.size(), layout.align()) as *mut u8
7280
}
7381
}
@@ -77,6 +85,13 @@ unsafe impl GlobalAlloc for MiMalloc {
7785
if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() {
7886
mi_zalloc(layout.size()) as *mut u8
7987
} else {
88+
#[cfg(target_os = "macos")]
89+
{
90+
if layout.align() > (1 << 31) {
91+
return ptr::null_mut()
92+
}
93+
}
94+
8095
mi_zalloc_aligned(layout.size(), layout.align()) as *mut u8
8196
}
8297
}

0 commit comments

Comments
 (0)