From 7777da379d35b10bee38b2faf218810552452130 Mon Sep 17 00:00:00 2001 From: worktycho Date: Sat, 17 May 2014 14:04:44 +0100 Subject: Fix assignment operators --- src/ChunkBuffer.h | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/ChunkBuffer.h b/src/ChunkBuffer.h index e16575bb2..1f170abba 100644 --- a/src/ChunkBuffer.h +++ b/src/ChunkBuffer.h @@ -53,21 +53,25 @@ public: other.IsOwner = false; } - void operator=(const cChunkBuffer& other) + cChunkBuffer& operator=(const cChunkBuffer& other) { - if(IsOwner) + if(&other == this) { + if(IsOwner) + { + for (int i = 0; i < CHUNK_SECTION_NUM; i++) + { + if(m_Sections[i]) Free(m_Sections[i]);; + } + } + IsOwner = true; for (int i = 0; i < CHUNK_SECTION_NUM; i++) { - if(m_Sections[i]) Free(m_Sections[i]);; + m_Sections[i] = other.m_Sections[i]; } + other.IsOwner = false; } - IsOwner = true; - for (int i = 0; i < CHUNK_SECTION_NUM; i++) - { - m_Sections[i] = other.m_Sections[i]; - } - other.IsOwner = false; + } #else // unique_ptr style interface for memory management @@ -79,7 +83,7 @@ public: } } - void operator=(const cChunkBuffer&& other) + cChunkBuffer& operator=(const cChunkBuffer&& other) { for (int i = 0; i < CHUNK_SECTION_NUM; i++) { -- cgit v1.2.3