diff options
author | worktycho <work.tycho@gmail.com> | 2014-05-17 15:04:44 +0200 |
---|---|---|
committer | worktycho <work.tycho@gmail.com> | 2014-05-17 15:04:44 +0200 |
commit | 7777da379d35b10bee38b2faf218810552452130 (patch) | |
tree | 284ba66b427f19eccf3fdf2a4f2175b03a3d3323 | |
parent | Add tests for assignment operator (diff) | |
download | cuberite-7777da379d35b10bee38b2faf218810552452130.tar cuberite-7777da379d35b10bee38b2faf218810552452130.tar.gz cuberite-7777da379d35b10bee38b2faf218810552452130.tar.bz2 cuberite-7777da379d35b10bee38b2faf218810552452130.tar.lz cuberite-7777da379d35b10bee38b2faf218810552452130.tar.xz cuberite-7777da379d35b10bee38b2faf218810552452130.tar.zst cuberite-7777da379d35b10bee38b2faf218810552452130.zip |
-rw-r--r-- | src/ChunkBuffer.h | 24 |
1 files changed, 14 insertions, 10 deletions
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++) { |