Commit 0a56e649 authored by Milo Yip's avatar Milo Yip

GenericValue: avoid memset/memcpy(this,...)

To avoid writing outside of the current GenericValue object and to
follow the C++ standard more closely, this patch drops the
memset/memcpy(this,...) occurences in GenericValue in favour of explicit
initialisations/assignments of the data_ and flag_ members.

https://code.google.com/p/rapidjson/issues/detail?id=11
https://github.com/pah/rapidjson/commit/7475a969
parent 4d94a805
......@@ -60,14 +60,13 @@ public:
\param type Type of the value.
\note Default content for number is zero.
*/
GenericValue(Type type) {
GenericValue(Type type) : data_() {
static const unsigned defaultFlags[7] = {
kNullFlag, kFalseFlag, kTrueFlag, kObjectFlag, kArrayFlag, kConstStringFlag,
kNumberFlag | kIntFlag | kUintFlag | kInt64Flag | kUint64Flag | kDoubleFlag
};
RAPIDJSON_ASSERT(type <= kNumberType);
flags_ = defaultFlags[type];
memset(&data_, 0, sizeof(data_));
}
//! Constructor for boolean value.
......@@ -170,8 +169,7 @@ public:
GenericValue& operator=(GenericValue& rhs) {
RAPIDJSON_ASSERT(this != &rhs);
this->~GenericValue();
memcpy(this, &rhs, sizeof(GenericValue));
rhs.flags_ = kNullFlag;
RawAssign(rhs);
return *this;
}
......@@ -677,7 +675,8 @@ private:
//! Assignment without calling destructor
void RawAssign(GenericValue& rhs) {
memcpy(this, &rhs, sizeof(GenericValue));
data_ = rhs.data_;
flags_ = rhs.flags_;
rhs.flags_ = kNullFlag;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment