Browse Source

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

JINMEI Tatuya 12 years ago
parent
commit
398b221538
1 changed files with 5 additions and 9 deletions
  1. 5 9
      src/lib/dns/labelsequence.cc

+ 5 - 9
src/lib/dns/labelsequence.cc

@@ -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);
 }