From acc952d839d88a9904b259f10e5fa4c047119786 Mon Sep 17 00:00:00 2001 From: shenweip <1037567878@qq.com> Date: Wed, 5 Aug 2020 18:43:45 +0800 Subject: [PATCH 1/2] Correct the alignment size when allocate memory at a position. --- Core/Util/BlockAllocator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/Util/BlockAllocator.cpp b/Core/Util/BlockAllocator.cpp index 02496432b1..34bf5ee618 100644 --- a/Core/Util/BlockAllocator.cpp +++ b/Core/Util/BlockAllocator.cpp @@ -163,7 +163,7 @@ u32 BlockAllocator::AllocAt(u32 position, u32 size, const char *tag) alignedPosition &= ~(grain_ - 1); // Since the position was decreased, size must increase. - alignedSize += alignedPosition - position; + alignedSize += position - alignedPosition; } // Upalign size to grain. From 77da51c41820f5836209c380bfac687abbce2fcf Mon Sep 17 00:00:00 2001 From: shenweip <1037567878@qq.com> Date: Wed, 5 Aug 2020 19:01:00 +0800 Subject: [PATCH 2/2] Also correct the allocated size. --- Core/Util/BlockAllocator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/Util/BlockAllocator.cpp b/Core/Util/BlockAllocator.cpp index 34bf5ee618..1b67b82a9a 100644 --- a/Core/Util/BlockAllocator.cpp +++ b/Core/Util/BlockAllocator.cpp @@ -169,7 +169,7 @@ u32 BlockAllocator::AllocAt(u32 position, u32 size, const char *tag) // Upalign size to grain. alignedSize = (alignedSize + grain_ - 1) & ~(grain_ - 1); // Tell the caller the allocated size from their requested starting position. - size = alignedSize - (alignedPosition - position); + size = alignedSize - (position - alignedPosition); Block *bp = GetBlockFromAddress(alignedPosition); if (bp != NULL)