Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/miloyip/rapidjson.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormiloyip <miloyip@gmail.com>2014-07-31 15:08:37 +0400
committermiloyip <miloyip@gmail.com>2014-07-31 15:08:37 +0400
commitafe59a0db16703dc5e62f3a821e5192be4973ece (patch)
tree584e85c540d99ea5e1a9ec2ee3ce1e750d20f54b /include
parent71ae5660eded26b3ef637f220a48abb412dde229 (diff)
Makes `StringEqual()` more safe by always compares lengths.
Diffstat (limited to 'include')
-rw-r--r--include/rapidjson/document.h5
1 files changed, 3 insertions, 2 deletions
diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h
index 16167ff4..c231385c 100644
--- a/include/rapidjson/document.h
+++ b/include/rapidjson/document.h
@@ -1281,8 +1281,9 @@ private:
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_;