From de9c09c42db0cae5dee606e38759b520dc0266c4 Mon Sep 17 00:00:00 2001 From: Yihao Shao <74238076+shaoyihao@users.noreply.github.com> Date: Mon, 1 Jun 2026 16:38:14 +0800 Subject: [PATCH] Fix argument order in std::aligned_alloc calls The C++ standard library specifies std::aligned_alloc(alignment, size). The previous implementation reversed these arguments, which passes the requested size as the alignment requirement (likely causing allocation failures if the size is not a power of two) and allocates the wrong amount of memory. --- junction/new_override.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/junction/new_override.cc b/junction/new_override.cc index 8122d597..cc3660c0 100644 --- a/junction/new_override.cc +++ b/junction/new_override.cc @@ -43,14 +43,14 @@ __always_inline void *do_new_aligned(size_t size, std::align_val_t a) { auto align = static_cast(a); // Handle the case where the runtime is not initialized - if (unlikely(!runtime.ready)) return std::aligned_alloc(size, align); + if (unlikely(!runtime.ready)) return std::aligned_alloc(align, size); size_t aligned = AlignUp(size, align); // Handle the case where the object being allocated is large if (unlikely(aligned >= kMaxAllocSize)) { rt::RuntimeLibcGuard guard; - return std::aligned_alloc(size, align); + return std::aligned_alloc(align, size); } // Hot path: Handle typical allocations using the runtime