Commit 398b2215 authored by JINMEI Tatuya's avatar JINMEI Tatuya Committed by Mukund Sivaraman
Browse files

[2053] Use getDataLength() to find out the right end to stop

parent 23ae3c2b
......@@ -116,23 +116,18 @@ std::string
LabelSequence::toText(bool omit_final_dot) const {
Name::NameString::const_iterator np = name_.ndata_.begin() +
name_.offsets_[first_label_];
const Name::NameString::const_iterator np_end = name_.ndata_.end();
const Name::NameString::const_iterator np_end = np + getDataLength();
// use for integrity check
unsigned int labels = last_label_ - first_label_;
// init with an impossible value to catch error cases in the end:
unsigned int count = Name::MAX_LABELLEN + 1;
// result string: it will roughly have the same length as the wire format
// name data. reserve that length to minimize reallocation.
// label sequence data. reserve that length to minimize reallocation.
std::string result;
result.reserve(name_.getLength());
result.reserve(getDataLength());
while (np != np_end) {
if (labels == 0) {
count = 0;
break;
}
labels--;
count = *np++;
......@@ -187,8 +182,9 @@ LabelSequence::toText(bool omit_final_dot) const {
}
}
// We should be at the end of the data and have consumed all labels.
assert(np == np_end);
assert(labels == 0);
assert(count == 0);
return (result);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment