Skip to content

Commit e1a3c64

Browse files
vslashgbaylesj
andauthored
Fix asserts in Value::setComment (#1445)
The existing asserts seem to not be what was intended; they appear to have been mistranslated in pull/877. The first assert for `comment.empty()` was previously a check that a provided `const char*` parameter was not null. The function this replaced accepted empty strings, and the if() statement at the start of this function handles them. The second assert for `comment[0] == '\0'` was written when `comment` was a `const char*`, and was testing for empty c-string input. This PR replaces it with `comment.empty()` to match the original intent. Co-authored-by: Jordan Bayles <[email protected]>
1 parent 3c2205c commit e1a3c64

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

src/lib_json/json_value.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,9 +1410,8 @@ void Value::setComment(String comment, CommentPlacement placement) {
14101410
// Always discard trailing newline, to aid indentation.
14111411
comment.pop_back();
14121412
}
1413-
JSON_ASSERT(!comment.empty());
14141413
JSON_ASSERT_MESSAGE(
1415-
comment[0] == '\0' || comment[0] == '/',
1414+
comment.empty() || comment[0] == '/',
14161415
"in Json::Value::setComment(): Comments must start with /");
14171416
comments_.set(placement, std::move(comment));
14181417
}

0 commit comments

Comments
 (0)