From 2e4db0d130245fb9dcd770a93fd22e04c0035cd7 Mon Sep 17 00:00:00 2001 From: Marsman Date: Sat, 7 Feb 2026 10:55:39 +0000 Subject: [PATCH] fix: return EINVAL when alignment is 0 --- src/header/stdlib/mod.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/header/stdlib/mod.rs b/src/header/stdlib/mod.rs index f6698fe7da..5c2d0e1faf 100644 --- a/src/header/stdlib/mod.rs +++ b/src/header/stdlib/mod.rs @@ -142,14 +142,13 @@ pub extern "C" fn abs(i: c_int) -> c_int { /// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn aligned_alloc(alignment: size_t, size: size_t) -> *mut c_void { - if size % alignment == 0 { - /* The size-is-multiple-of-alignment requirement is the only - * difference between aligned_alloc() and memalign(). */ - unsafe { memalign(alignment, size) } - } else { + if alignment == 0 || size % alignment != 0 { platform::ERRNO.set(EINVAL); - ptr::null_mut() + return ptr::null_mut(); } + /* The size-is-multiple-of-alignment requirement is the only + * difference between aligned_alloc() and memalign(). */ + unsafe { memalign(alignment, size) } } /// See .