From afe59a0db16703dc5e62f3a821e5192be4973ece Mon Sep 17 00:00:00 2001 From: miloyip Date: Thu, 31 Jul 2014 19:08:37 +0800 Subject: [PATCH] Makes `StringEqual()` more safe by always compares lengths. --- include/rapidjson/document.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 16167ff..c231385 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_;