From d03333535059b80ed2a0ffb61677a48b9eb570b8 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Thu, 7 Nov 2019 00:33:34 -0600 Subject: [PATCH] [ox/ptrarith] Make NodeBuffer clear all memory before using it --- deps/ox/src/ox/ptrarith/nodebuffer.hpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/deps/ox/src/ox/ptrarith/nodebuffer.hpp b/deps/ox/src/ox/ptrarith/nodebuffer.hpp index 5392991f..bf92b925 100644 --- a/deps/ox/src/ox/ptrarith/nodebuffer.hpp +++ b/deps/ox/src/ox/ptrarith/nodebuffer.hpp @@ -93,8 +93,7 @@ class __attribute__((packed)) NodeBuffer { Header m_header; public: - NodeBuffer() { - } + NodeBuffer(); NodeBuffer(const NodeBuffer &other, size_t size); @@ -169,12 +168,16 @@ class __attribute__((packed)) NodeBuffer { template NodeBuffer::NodeBuffer(size_t size) { m_header.size = size; + auto data = reinterpret_cast(this) + sizeof(*this); + ox_memset(data, 0, size - sizeof(*this)); oxTrace("ox::NodeBuffer::constructor") << m_header.firstItem; } template NodeBuffer::NodeBuffer(const NodeBuffer &other, size_t size) { oxTrace("ox::ptrarith::NodeBuffer::copy") << "other.m_header.firstItem:" << other.m_header.firstItem; + auto data = reinterpret_cast(this) + sizeof(*this); + ox_memset(data, 0, size - sizeof(*this)); ox_memcpy(this, &other, size); } @@ -286,6 +289,7 @@ typename NodeBuffer::ItemPtr NodeBuffer::malloc(size oxTrace("ox::ptrarith::NodeBuffer::malloc::fail") << "Unknown"; return nullptr; } + ox_memset(out, 0, fullSize); new (out) Item; out->setSize(size); @@ -360,6 +364,8 @@ Error NodeBuffer::setSize(size_t size) { return OxError(1); } else { m_header.size = size; + auto data = reinterpret_cast(this) + end; + ox_memset(data, 0, size - end); return OxError(0); } }