diff options
| author | Stefan Boberg <[email protected]> | 2023-06-16 18:47:04 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2023-06-16 18:47:04 +0200 |
| commit | ccab13777524eb8274fa617918fc0b8fadd14e05 (patch) | |
| tree | 9e2c688a97f11e2dcf1b1a0323df191e28ffa2ea | |
| parent | cleaned up http/asio logging (diff) | |
| download | zen-ccab13777524eb8274fa617918fc0b8fadd14e05.tar.xz zen-ccab13777524eb8274fa617918fc0b8fadd14e05.zip | |
MakeCloneFromMemory should handle zero sized buffers gracefully
we don't currently permit creating zero-length IoBuffer instances to prevent inefficiencies, but this can cause issues since some higher level code now ends up using it for things it was not originally intended for.
| -rw-r--r-- | src/zencore/include/zencore/iobuffer.h | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/zencore/include/zencore/iobuffer.h b/src/zencore/include/zencore/iobuffer.h index 49f9f9e2c..2f248eb8b 100644 --- a/src/zencore/include/zencore/iobuffer.h +++ b/src/zencore/include/zencore/iobuffer.h @@ -414,8 +414,15 @@ public: /** Make sure buffer data is memory resident, but avoid memory mapping data from files */ ZENCORE_API static IoBuffer ReadFromFileMaybe(IoBuffer& InBuffer); - inline static IoBuffer MakeCloneFromMemory(const void* Ptr, size_t Sz) { return IoBuffer(IoBuffer::Clone, Ptr, Sz); } - inline static IoBuffer MakeCloneFromMemory(MemoryView Memory) { return IoBuffer(IoBuffer::Clone, Memory.GetData(), Memory.GetSize()); } + inline static IoBuffer MakeCloneFromMemory(const void* Ptr, size_t Sz) + { + if (Sz) + { + return IoBuffer(IoBuffer::Clone, Ptr, Sz); + } + return {}; + } + inline static IoBuffer MakeCloneFromMemory(MemoryView Memory) { return MakeCloneFromMemory(Memory.GetData(), Memory.GetSize()); } }; IoHash HashBuffer(IoBuffer& Buffer); |