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
This commit is contained in:
parent
4d94a8057d
commit
0a56e6496f
@ -60,14 +60,13 @@ public:
|
|||||||
\param type Type of the value.
|
\param type Type of the value.
|
||||||
\note Default content for number is zero.
|
\note Default content for number is zero.
|
||||||
*/
|
*/
|
||||||
GenericValue(Type type) {
|
GenericValue(Type type) : data_() {
|
||||||
static const unsigned defaultFlags[7] = {
|
static const unsigned defaultFlags[7] = {
|
||||||
kNullFlag, kFalseFlag, kTrueFlag, kObjectFlag, kArrayFlag, kConstStringFlag,
|
kNullFlag, kFalseFlag, kTrueFlag, kObjectFlag, kArrayFlag, kConstStringFlag,
|
||||||
kNumberFlag | kIntFlag | kUintFlag | kInt64Flag | kUint64Flag | kDoubleFlag
|
kNumberFlag | kIntFlag | kUintFlag | kInt64Flag | kUint64Flag | kDoubleFlag
|
||||||
};
|
};
|
||||||
RAPIDJSON_ASSERT(type <= kNumberType);
|
RAPIDJSON_ASSERT(type <= kNumberType);
|
||||||
flags_ = defaultFlags[type];
|
flags_ = defaultFlags[type];
|
||||||
memset(&data_, 0, sizeof(data_));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Constructor for boolean value.
|
//! Constructor for boolean value.
|
||||||
@ -170,8 +169,7 @@ public:
|
|||||||
GenericValue& operator=(GenericValue& rhs) {
|
GenericValue& operator=(GenericValue& rhs) {
|
||||||
RAPIDJSON_ASSERT(this != &rhs);
|
RAPIDJSON_ASSERT(this != &rhs);
|
||||||
this->~GenericValue();
|
this->~GenericValue();
|
||||||
memcpy(this, &rhs, sizeof(GenericValue));
|
RawAssign(rhs);
|
||||||
rhs.flags_ = kNullFlag;
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -677,7 +675,8 @@ private:
|
|||||||
|
|
||||||
//! Assignment without calling destructor
|
//! Assignment without calling destructor
|
||||||
void RawAssign(GenericValue& rhs) {
|
void RawAssign(GenericValue& rhs) {
|
||||||
memcpy(this, &rhs, sizeof(GenericValue));
|
data_ = rhs.data_;
|
||||||
|
flags_ = rhs.flags_;
|
||||||
rhs.flags_ = kNullFlag;
|
rhs.flags_ = kNullFlag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user