Skip to content

Commit 8a77037

Browse files
committed
actually store length in CZString
1 parent 57ad051 commit 8a77037

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

include/json/value.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class JSON_API Value {
164164
duplicateOnCopy
165165
};
166166
CZString(ArrayIndex index);
167-
CZString(const char* cstr, DuplicationPolicy allocate);
167+
CZString(char const* cstr, unsigned length, DuplicationPolicy allocate);
168168
CZString(const CZString& other);
169169
~CZString();
170170
CZString& operator=(CZString other);

src/lib_json/json_value.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ void Value::CommentInfo::setComment(const char* text, size_t len) {
163163

164164
Value::CZString::CZString(ArrayIndex index) : cstr_(0), index_(index) {}
165165

166-
Value::CZString::CZString(const char* cstr, DuplicationPolicy allocate)
167-
: cstr_(allocate == duplicate ? duplicateStringValue(cstr) : cstr),
168-
storage_({allocate, 0})
166+
Value::CZString::CZString(char const* str, unsigned length, DuplicationPolicy allocate)
167+
: cstr_(allocate == duplicate ? duplicateStringValue(str) : str),
168+
storage_({allocate, length})
169169
{}
170170

171171
Value::CZString::CZString(const CZString& other)
@@ -175,7 +175,7 @@ Value::CZString::CZString(const CZString& other)
175175
storage_({(other.cstr_
176176
? (other.storage_.policy_ == noDuplication
177177
? noDuplication : duplicate)
178-
: other.storage_.policy_), 0})
178+
: other.storage_.policy_), other.storage_.length_})
179179
{}
180180

181181
Value::CZString::~CZString() {
@@ -849,7 +849,7 @@ Value& Value::resolveReference(const char* key, bool isStatic) {
849849
if (type_ == nullValue)
850850
*this = Value(objectValue);
851851
CZString actualKey(
852-
key, isStatic ? CZString::noDuplication : CZString::duplicateOnCopy);
852+
key, strlen(key), isStatic ? CZString::noDuplication : CZString::duplicateOnCopy);
853853
ObjectValues::iterator it = value_.map_->lower_bound(actualKey);
854854
if (it != value_.map_->end() && (*it).first == actualKey)
855855
return (*it).second;
@@ -873,7 +873,7 @@ const Value& Value::operator[](const char* key) const {
873873
"in Json::Value::operator[](char const*)const: requires objectValue");
874874
if (type_ == nullValue)
875875
return null;
876-
CZString actualKey(key, CZString::noDuplication);
876+
CZString actualKey(key, strlen(key), CZString::noDuplication);
877877
ObjectValues::const_iterator it = value_.map_->find(actualKey);
878878
if (it == value_.map_->end())
879879
return null;
@@ -918,7 +918,7 @@ bool Value::removeMember(const char* key, Value* removed) {
918918
if (type_ != objectValue) {
919919
return false;
920920
}
921-
CZString actualKey(key, CZString::noDuplication);
921+
CZString actualKey(key, strlen(key), CZString::noDuplication);
922922
ObjectValues::iterator it = value_.map_->find(actualKey);
923923
if (it == value_.map_->end())
924924
return false;

0 commit comments

Comments
 (0)