aboutsummaryrefslogtreecommitdiff
path: root/src/zencore/memory.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2023-08-01 09:37:59 +0200
committerGitHub <[email protected]>2023-08-01 09:37:59 +0200
commit4df6c9241b39bc9103782bc64ea90ae821ee9108 (patch)
treedfc69f41b544cf818e5821ccf9e6c60cf01d759b /src/zencore/memory.cpp
parentadd requested item in oplog remote op (#340) (diff)
downloadzen-4df6c9241b39bc9103782bc64ea90ae821ee9108.tar.xz
zen-4df6c9241b39bc9103782bc64ea90ae821ee9108.zip
make sure we validate pointers returned from zen::Memory::Alloc (#341)
* make sure we validate pointers returned from zen::Memory::Alloc
Diffstat (limited to 'src/zencore/memory.cpp')
-rw-r--r--src/zencore/memory.cpp10
1 files changed, 8 insertions, 2 deletions
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 <zencore/except.h>
+#include <zencore/fmtutils.h>
#include <zencore/intmath.h>
#include <zencore/memory.h>
#include <zencore/testing.h>
@@ -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<uint8_t*>(ChunkPtr);
- m_ChunkBytesRemain = ChunkSize;
+ if (!ChunkPtr)
+ {
+ ThrowOutOfMemory(fmt::format("failed allocating {:#x} bytes aligned to {:#x}", ChunkSize, m_ChunkAlignment));
+ }
+ m_ChunkCursor = reinterpret_cast<uint8_t*>(ChunkPtr);
+ m_ChunkBytesRemain = ChunkSize;
m_ChunkList.push_back(ChunkPtr);
}