Skip to content

Commit 1b8e3b7

Browse files
committed
Merge pull request open-source-parsers#432 from ya1gaurav/patch-33
Avoid passing Null to memcmp hopefully resolves open-source-parsers#404
2 parents d179e24 + 4878913 commit 1b8e3b7

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/lib_json/json_value.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ bool Value::CZString::operator<(const CZString& other) const {
267267
unsigned this_len = this->storage_.length_;
268268
unsigned other_len = other.storage_.length_;
269269
unsigned min_len = std::min(this_len, other_len);
270+
JSON_ASSERT(this->cstr_ && other.cstr_);
270271
int comp = memcmp(this->cstr_, other.cstr_, min_len);
271272
if (comp < 0) return true;
272273
if (comp > 0) return false;
@@ -280,6 +281,7 @@ bool Value::CZString::operator==(const CZString& other) const {
280281
unsigned this_len = this->storage_.length_;
281282
unsigned other_len = other.storage_.length_;
282283
if (this_len != other_len) return false;
284+
JSON_ASSERT(this->cstr_ && other.cstr_);
283285
int comp = memcmp(this->cstr_, other.cstr_, this_len);
284286
return comp == 0;
285287
}
@@ -525,6 +527,7 @@ bool Value::operator<(const Value& other) const {
525527
decodePrefixedString(this->allocated_, this->value_.string_, &this_len, &this_str);
526528
decodePrefixedString(other.allocated_, other.value_.string_, &other_len, &other_str);
527529
unsigned min_len = std::min(this_len, other_len);
530+
JSON_ASSERT(this_str && other_str);
528531
int comp = memcmp(this_str, other_str, min_len);
529532
if (comp < 0) return true;
530533
if (comp > 0) return false;
@@ -580,6 +583,7 @@ bool Value::operator==(const Value& other) const {
580583
decodePrefixedString(this->allocated_, this->value_.string_, &this_len, &this_str);
581584
decodePrefixedString(other.allocated_, other.value_.string_, &other_len, &other_str);
582585
if (this_len != other_len) return false;
586+
JSON_ASSERT(this_str && other_str);
583587
int comp = memcmp(this_str, other_str, this_len);
584588
return comp == 0;
585589
}
@@ -914,7 +918,7 @@ void Value::resize(ArrayIndex newSize) {
914918
for (ArrayIndex index = newSize; index < oldSize; ++index) {
915919
value_.map_->erase(index);
916920
}
917-
assert(size() == newSize);
921+
JSON_ASSERT(size() == newSize);
918922
}
919923
}
920924

0 commit comments

Comments
 (0)