summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTycho <work.tycho+git@gmail.com>2014-05-30 15:43:33 +0200
committerTycho <work.tycho+git@gmail.com>2014-05-30 15:43:33 +0200
commitd854d3af1c724304997488d2b61518c85acb076a (patch)
tree396012aded70435c6dc63963c09972d5ec8107f2 /src
parentFixed cChunkData nibble copying. (diff)
downloadcuberite-d854d3af1c724304997488d2b61518c85acb076a.tar
cuberite-d854d3af1c724304997488d2b61518c85acb076a.tar.gz
cuberite-d854d3af1c724304997488d2b61518c85acb076a.tar.bz2
cuberite-d854d3af1c724304997488d2b61518c85acb076a.tar.lz
cuberite-d854d3af1c724304997488d2b61518c85acb076a.tar.xz
cuberite-d854d3af1c724304997488d2b61518c85acb076a.tar.zst
cuberite-d854d3af1c724304997488d2b61518c85acb076a.zip
Diffstat (limited to '')
-rw-r--r--src/ChunkData.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/ChunkData.cpp b/src/ChunkData.cpp
index 6178dbc0d..258853ea0 100644
--- a/src/ChunkData.cpp
+++ b/src/ChunkData.cpp
@@ -55,6 +55,7 @@ cChunkData::~cChunkData()
for (size_t i = 0; i < NumSections; i++)
{
Free(m_Sections[i]);
+ m_Sections[i] = NULL;
}
}
@@ -93,6 +94,7 @@ cChunkData::~cChunkData()
for (size_t i = 0; i < NumSections; i++)
{
Free(m_Sections[i]);
+ m_Sections[i] = NULL;
}
}
@@ -101,6 +103,7 @@ cChunkData::~cChunkData()
for (size_t i = 0; i < NumSections; i++)
{
m_Sections[i] = a_Other.m_Sections[i];
+ a_Other.m_Sections[i] = NULL;
}
a_Other.m_IsOwner = false;
return *this;
@@ -333,27 +336,28 @@ cChunkData cChunkData::Copy(void) const
void cChunkData::CopyBlockTypes(BLOCKTYPE * a_Dest, size_t a_Idx, size_t a_Length) const
{
- int ToSkip = a_Idx;
+ size_t ToSkip = a_Idx;
for (size_t i = 0; i < NumSections; i++)
{
size_t StartPos = 0;
if (ToSkip > 0)
{
- ToSkip = std::max(ToSkip - (int)SectionBlockCount, 0);
- StartPos = SectionBlockCount - ToSkip;
+ StartPos = std::min(ToSkip, +SectionBlockCount);
+ ToSkip -= StartPos;
}
- if (ToSkip < (int)SectionBlockCount)
+ if (StartPos < SectionBlockCount)
{
- size_t ToCopy = std::min(+SectionBlockCount, a_Length);
+ size_t ToCopy = std::min(+SectionBlockCount - StartPos, a_Length);
a_Length -= ToCopy;
if (m_Sections[i] != NULL)
{
- memcpy(&a_Dest[(i * SectionBlockCount) - a_Idx], (&m_Sections[i]->m_BlockTypes) + StartPos, sizeof(BLOCKTYPE) * (ToCopy - StartPos));
+ BLOCKTYPE * blockbuffer = m_Sections[i]->m_BlockTypes;
+ memcpy(&a_Dest[(i * SectionBlockCount) + StartPos - a_Idx], blockbuffer + StartPos, sizeof(BLOCKTYPE) * ToCopy);
}
else
{
- memset(&a_Dest[(i * SectionBlockCount) - a_Idx], 0, sizeof(BLOCKTYPE) * (ToCopy - StartPos));
+ memset(&a_Dest[(i * SectionBlockCount) - a_Idx], 0, sizeof(BLOCKTYPE) * ToCopy);
}
}
}