Skip to content

Fix uninitialized value detected by valgrind #580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib_json/json_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Reader::Reader(const Features& features)

bool
Reader::parse(const std::string& document, Value& root, bool collectComments) {
JSONCPP_STRING documentCopy(document.data(), document.data() + document.capacity());
JSONCPP_STRING documentCopy(document.data(), document.data() + document.length());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSONCPP_STRING is going to be some kind of std::basic_string. The allocator changes with different build configurations. So it has the full std::string constructor API.

JSONCPP_STRING documentCopy(document.begin(), document.end());

But really we don't need documentCopy at all. The swap doesn't seem to be doing anything we can't do better with an assignment.

document_.assign(document.begin(), document.end());

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @BillyDonahue.

std::swap(documentCopy, document_);
const char* begin = document_.c_str();
const char* end = begin + document_.length();
Expand Down