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

Conversation

ya1gaurav
Copy link
Contributor

Fix issue reported in #578
For std::string variable, length() is more readable than size().

Fix issue reported in open-source-parsers#578
For std::string variable, length() is more readable than size().
@BillyDonahue
Copy link
Contributor

BillyDonahue commented Feb 15, 2017

I disagree about the "readability" of length vs size, as size is part of the container requirements and is more widely used throughout C++ containerdom. I believe the synonym length is a holdover from the pre-STL string class. Not that it matters, but that's my $0.02.

@@ -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.

@cdunn2001 cdunn2001 mentioned this pull request Aug 27, 2017
@cdunn2001 cdunn2001 closed this in 74438d1 Aug 27, 2017
cdunn2001 added a commit that referenced this pull request Aug 27, 2017
But simply use `.assign()` instead of the extra copy. (See comment from
@BillyDonhue at #580.)

fixes #578
closes #580
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants