aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2023-12-14 04:16:25 -0500
committerGitHub <[email protected]>2023-12-14 10:16:25 +0100
commit4d96ef4d9d2c35243a25d90949d43d0997e3bb44 (patch)
tree5f398e0027886aed3d12b625b89014ef83fb8abd /src
parent0.2.37-pre1 (diff)
downloadzen-4d96ef4d9d2c35243a25d90949d43d0997e3bb44.tar.xz
zen-4d96ef4d9d2c35243a25d90949d43d0997e3bb44.zip
Make sure IoBuffer is a valid null-buffer after move operation (#610)
Diffstat (limited to 'src')
-rw-r--r--src/zenbase/include/zenbase/refcount.h2
-rw-r--r--src/zencore/include/zencore/iobuffer.h17
2 files changed, 15 insertions, 4 deletions
diff --git a/src/zenbase/include/zenbase/refcount.h b/src/zenbase/include/zenbase/refcount.h
index 3afcf467c..6ad49cba2 100644
--- a/src/zenbase/include/zenbase/refcount.h
+++ b/src/zenbase/include/zenbase/refcount.h
@@ -107,6 +107,8 @@ public:
Rhs.m_Ref = nullptr;
}
+ inline void Swap(RefPtr& Rhs) noexcept { std::swap(m_Ref, Rhs.m_Ref); }
+
private:
T* m_Ref = nullptr;
template<typename U>
diff --git a/src/zencore/include/zencore/iobuffer.h b/src/zencore/include/zencore/iobuffer.h
index d891ed55b..b9e503354 100644
--- a/src/zencore/include/zencore/iobuffer.h
+++ b/src/zencore/include/zencore/iobuffer.h
@@ -337,11 +337,20 @@ public:
BorrowedFile
};
- inline IoBuffer() = default;
- inline IoBuffer(IoBuffer&& Rhs) noexcept = default;
- inline IoBuffer(const IoBuffer& Rhs) = default;
+ inline IoBuffer() = default;
+ inline IoBuffer(IoBuffer&& Rhs) noexcept
+ {
+ m_Core.Swap(Rhs.m_Core);
+ Rhs.m_Core = NullBufferCore;
+ }
+ inline IoBuffer(const IoBuffer& Rhs) = default;
inline IoBuffer& operator=(const IoBuffer& Rhs) = default;
- inline IoBuffer& operator=(IoBuffer&& Rhs) noexcept = default;
+ inline IoBuffer& operator =(IoBuffer&& Rhs) noexcept
+ {
+ m_Core.Swap(Rhs.m_Core);
+ Rhs.m_Core = NullBufferCore;
+ return *this;
+ }
/** Create an uninitialized buffer of the given size
*/