From 4df6c9241b39bc9103782bc64ea90ae821ee9108 Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Tue, 1 Aug 2023 09:37:59 +0200 Subject: make sure we validate pointers returned from zen::Memory::Alloc (#341) * make sure we validate pointers returned from zen::Memory::Alloc --- src/zencore/memory.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/zencore/memory.cpp') diff --git a/src/zencore/memory.cpp b/src/zencore/memory.cpp index 1f148cede..546296b10 100644 --- a/src/zencore/memory.cpp +++ b/src/zencore/memory.cpp @@ -1,5 +1,7 @@ // Copyright Epic Games, Inc. All Rights Reserved. +#include +#include #include #include #include @@ -133,8 +135,12 @@ ChunkingLinearAllocator::Alloc(size_t Size, size_t Alignment) { const uint64_t ChunkSize = zen::RoundUp(zen::Max(m_ChunkSize, Size), m_ChunkSize); void* ChunkPtr = Memory::Alloc(ChunkSize, m_ChunkAlignment); - m_ChunkCursor = reinterpret_cast(ChunkPtr); - m_ChunkBytesRemain = ChunkSize; + if (!ChunkPtr) + { + ThrowOutOfMemory(fmt::format("failed allocating {:#x} bytes aligned to {:#x}", ChunkSize, m_ChunkAlignment)); + } + m_ChunkCursor = reinterpret_cast(ChunkPtr); + m_ChunkBytesRemain = ChunkSize; m_ChunkList.push_back(ChunkPtr); } -- cgit v1.2.3