Skip to content

Commit dbfcb85

Browse files
DefaultRawMemoryAllocator: fixed alignment in AllocateAligned
The alignment must be a power of two and a multiple of sizeof(void*))
1 parent 5196c52 commit dbfcb85

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Common/src/DefaultRawMemoryAllocator.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ void DefaultRawMemoryAllocator::Free(void* Ptr)
115115
void* DefaultRawMemoryAllocator::AllocateAligned(size_t Size, size_t Alignment, const Char* dbgDescription, const char* dbgFileName, const Int32 dbgLineNumber)
116116
{
117117
VERIFY_EXPR(Size > 0 && Alignment > 0);
118+
// Alignment must be a power of two and a multiple of sizeof(void*))
119+
Alignment = std::max(Alignment, sizeof(void*));
120+
// Size must be an integral multiple of alignment,
121+
// or aligned_alloc will return null
118122
Size = AlignUp(Size, Alignment);
119123
return ALIGNED_MALLOC(Size, Alignment, dbgFileName, dbgLineNumber);
120124
}

0 commit comments

Comments
 (0)