mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-18 19:29:09 +00:00
Tweak NetVaultNode::CopyFrom
- We now zero fields that are unused in the new copy - Ensure that blob fields are deep copied (fix potential crashes)
This commit is contained in:
@ -293,6 +293,27 @@ void NetGameRank::CopyFrom(const NetGameRank & fromRank) {
|
|||||||
*
|
*
|
||||||
***/
|
***/
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
|
void NetVaultNode::Blob::operator=(const Blob& rhs)
|
||||||
|
{
|
||||||
|
if (size != rhs.size) {
|
||||||
|
delete[] buffer;
|
||||||
|
buffer = new uint8_t[rhs.size];
|
||||||
|
size = rhs.size;
|
||||||
|
}
|
||||||
|
memcpy(buffer, rhs.buffer, rhs.size);
|
||||||
|
}
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
|
void NetVaultNode::Blob::operator=(Blob&& rhs)
|
||||||
|
{
|
||||||
|
delete[] buffer;
|
||||||
|
size = rhs.size;
|
||||||
|
buffer = rhs.buffer;
|
||||||
|
rhs.size = 0;
|
||||||
|
rhs.buffer = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
bool NetVaultNode::Blob::operator==(const Blob& rhs) const
|
bool NetVaultNode::Blob::operator==(const Blob& rhs) const
|
||||||
{
|
{
|
||||||
@ -312,46 +333,78 @@ void NetVaultNode::Clear()
|
|||||||
}
|
}
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
template<typename T>
|
||||||
|
static void IZero(T& dest)
|
||||||
|
{
|
||||||
|
dest = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
static void IZero<plString>(plString& dest)
|
||||||
|
{
|
||||||
|
dest = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
static void IZero<plUUID>(plUUID& dest)
|
||||||
|
{
|
||||||
|
dest = kNilUuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
static void IZero<NetVaultNode::Blob>(NetVaultNode::Blob& blob)
|
||||||
|
{
|
||||||
|
delete[] blob.buffer;
|
||||||
|
blob.buffer = nullptr;
|
||||||
|
blob.size = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void NetVaultNode::CopyFrom(const NetVaultNode* node)
|
void NetVaultNode::CopyFrom(const NetVaultNode* node)
|
||||||
{
|
{
|
||||||
fUsedFields = node->fUsedFields;
|
fUsedFields = node->fUsedFields;
|
||||||
fDirtyFields = node->fDirtyFields;
|
fDirtyFields = node->fDirtyFields;
|
||||||
fRevision = node->fRevision;
|
fRevision = node->fRevision;
|
||||||
|
|
||||||
#define COPY(field) f##field = node->f##field
|
#define COPYORZERO(field) \
|
||||||
COPY(NodeId);
|
if (fUsedFields & k##field) \
|
||||||
COPY(CreateTime);
|
f##field = node->f##field; \
|
||||||
COPY(ModifyTime);
|
else \
|
||||||
COPY(CreateAgeName);
|
IZero(f##field);
|
||||||
COPY(CreateAgeUuid);
|
|
||||||
COPY(CreatorAcct);
|
COPYORZERO(NodeId);
|
||||||
COPY(CreatorId);
|
COPYORZERO(CreateTime);
|
||||||
COPY(NodeType);
|
COPYORZERO(ModifyTime);
|
||||||
COPY(Int32_1);
|
COPYORZERO(CreateAgeName);
|
||||||
COPY(Int32_2);
|
COPYORZERO(CreateAgeUuid);
|
||||||
COPY(Int32_3);
|
COPYORZERO(CreatorAcct);
|
||||||
COPY(Int32_4);
|
COPYORZERO(CreatorId);
|
||||||
COPY(UInt32_1);
|
COPYORZERO(NodeType);
|
||||||
COPY(UInt32_2);
|
COPYORZERO(Int32_1);
|
||||||
COPY(UInt32_3);
|
COPYORZERO(Int32_2);
|
||||||
COPY(UInt32_4);
|
COPYORZERO(Int32_3);
|
||||||
COPY(Uuid_1);
|
COPYORZERO(Int32_4);
|
||||||
COPY(Uuid_2);
|
COPYORZERO(UInt32_1);
|
||||||
COPY(Uuid_3);
|
COPYORZERO(UInt32_2);
|
||||||
COPY(Uuid_4);
|
COPYORZERO(UInt32_3);
|
||||||
COPY(String64_1);
|
COPYORZERO(UInt32_4);
|
||||||
COPY(String64_2);
|
COPYORZERO(Uuid_1);
|
||||||
COPY(String64_3);
|
COPYORZERO(Uuid_2);
|
||||||
COPY(String64_4);
|
COPYORZERO(Uuid_3);
|
||||||
COPY(String64_5);
|
COPYORZERO(Uuid_4);
|
||||||
COPY(String64_6);
|
COPYORZERO(String64_1);
|
||||||
COPY(IString64_1);
|
COPYORZERO(String64_2);
|
||||||
COPY(IString64_2);
|
COPYORZERO(String64_3);
|
||||||
COPY(Text_1);
|
COPYORZERO(String64_4);
|
||||||
COPY(Text_2);
|
COPYORZERO(String64_5);
|
||||||
COPY(Blob_1);
|
COPYORZERO(String64_6);
|
||||||
COPY(Blob_2);
|
COPYORZERO(IString64_1);
|
||||||
#undef COPY
|
COPYORZERO(IString64_2);
|
||||||
|
COPYORZERO(Text_1);
|
||||||
|
COPYORZERO(Text_2);
|
||||||
|
COPYORZERO(Blob_1);
|
||||||
|
COPYORZERO(Blob_2);
|
||||||
|
|
||||||
|
#undef COPYORZERO
|
||||||
}
|
}
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
@ -212,6 +212,9 @@ public:
|
|||||||
Blob() : size(0), buffer(nullptr) { }
|
Blob() : size(0), buffer(nullptr) { }
|
||||||
~Blob() { delete[] buffer; }
|
~Blob() { delete[] buffer; }
|
||||||
|
|
||||||
|
void operator =(const Blob& rhs);
|
||||||
|
void operator =(Blob&& rhs);
|
||||||
|
|
||||||
bool operator ==(const Blob& rhs) const;
|
bool operator ==(const Blob& rhs) const;
|
||||||
bool operator !=(const Blob& rhs) const { return !operator==(rhs); }
|
bool operator !=(const Blob& rhs) const { return !operator==(rhs); }
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user