[ox/ptrarith] Make NodeBuffer clear all memory before using it
This commit is contained in:
parent
3cc6ca215e
commit
d033335350
10
deps/ox/src/ox/ptrarith/nodebuffer.hpp
vendored
10
deps/ox/src/ox/ptrarith/nodebuffer.hpp
vendored
@ -93,8 +93,7 @@ class __attribute__((packed)) NodeBuffer {
|
|||||||
Header m_header;
|
Header m_header;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NodeBuffer() {
|
NodeBuffer();
|
||||||
}
|
|
||||||
|
|
||||||
NodeBuffer(const NodeBuffer &other, size_t size);
|
NodeBuffer(const NodeBuffer &other, size_t size);
|
||||||
|
|
||||||
@ -169,12 +168,16 @@ class __attribute__((packed)) NodeBuffer {
|
|||||||
template<typename size_t, typename Item>
|
template<typename size_t, typename Item>
|
||||||
NodeBuffer<size_t, Item>::NodeBuffer(size_t size) {
|
NodeBuffer<size_t, Item>::NodeBuffer(size_t size) {
|
||||||
m_header.size = size;
|
m_header.size = size;
|
||||||
|
auto data = reinterpret_cast<uint8_t*>(this) + sizeof(*this);
|
||||||
|
ox_memset(data, 0, size - sizeof(*this));
|
||||||
oxTrace("ox::NodeBuffer::constructor") << m_header.firstItem;
|
oxTrace("ox::NodeBuffer::constructor") << m_header.firstItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename size_t, typename Item>
|
template<typename size_t, typename Item>
|
||||||
NodeBuffer<size_t, Item>::NodeBuffer(const NodeBuffer &other, size_t size) {
|
NodeBuffer<size_t, Item>::NodeBuffer(const NodeBuffer &other, size_t size) {
|
||||||
oxTrace("ox::ptrarith::NodeBuffer::copy") << "other.m_header.firstItem:" << other.m_header.firstItem;
|
oxTrace("ox::ptrarith::NodeBuffer::copy") << "other.m_header.firstItem:" << other.m_header.firstItem;
|
||||||
|
auto data = reinterpret_cast<uint8_t*>(this) + sizeof(*this);
|
||||||
|
ox_memset(data, 0, size - sizeof(*this));
|
||||||
ox_memcpy(this, &other, size);
|
ox_memcpy(this, &other, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,6 +289,7 @@ typename NodeBuffer<size_t, Item>::ItemPtr NodeBuffer<size_t, Item>::malloc(size
|
|||||||
oxTrace("ox::ptrarith::NodeBuffer::malloc::fail") << "Unknown";
|
oxTrace("ox::ptrarith::NodeBuffer::malloc::fail") << "Unknown";
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
ox_memset(out, 0, fullSize);
|
||||||
new (out) Item;
|
new (out) Item;
|
||||||
out->setSize(size);
|
out->setSize(size);
|
||||||
|
|
||||||
@ -360,6 +364,8 @@ Error NodeBuffer<size_t, Item>::setSize(size_t size) {
|
|||||||
return OxError(1);
|
return OxError(1);
|
||||||
} else {
|
} else {
|
||||||
m_header.size = size;
|
m_header.size = size;
|
||||||
|
auto data = reinterpret_cast<uint8_t*>(this) + end;
|
||||||
|
ox_memset(data, 0, size - end);
|
||||||
return OxError(0);
|
return OxError(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user