Commit afe59a0d authored by miloyip's avatar miloyip

Makes `StringEqual()` more safe by always compares lengths.

parent 71ae5660
...@@ -1281,8 +1281,9 @@ private: ...@@ -1281,8 +1281,9 @@ private:
bool StringEqual(const GenericValue& rhs) const { bool StringEqual(const GenericValue& rhs) const {
RAPIDJSON_ASSERT(IsString()); RAPIDJSON_ASSERT(IsString());
RAPIDJSON_ASSERT(rhs.IsString()); RAPIDJSON_ASSERT(rhs.IsString());
return data_.s.str == rhs.data_.s.str || // fast path for constant string return data_.s.length == rhs.data_.s.length &&
((data_.s.length == rhs.data_.s.length) && memcmp(data_.s.str, rhs.data_.s.str, sizeof(Ch) * data_.s.length) == 0); (data_.s.str == rhs.data_.s.str // fast path for constant string
|| memcmp(data_.s.str, rhs.data_.s.str, sizeof(Ch) * data_.s.length) == 0);
} }
Data data_; Data data_;
......
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