Skip to content

Commit

Permalink
Makes StringEqual() more safe by always compares lengths.
Browse files Browse the repository at this point in the history
  • Loading branch information
miloyip committed Jul 31, 2014
1 parent 71ae566 commit afe59a0
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions include/rapidjson/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -1281,8 +1281,9 @@ int z = a[0u].GetInt(); // This works too.
bool StringEqual(const GenericValue& rhs) const {
RAPIDJSON_ASSERT(IsString());
RAPIDJSON_ASSERT(rhs.IsString());
return data_.s.str == rhs.data_.s.str || // fast path for constant string
((data_.s.length == rhs.data_.s.length) && memcmp(data_.s.str, rhs.data_.s.str, sizeof(Ch) * data_.s.length) == 0);
return data_.s.length == rhs.data_.s.length &&
(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_;
Expand Down

0 comments on commit afe59a0

Please sign in to comment.