Browse Source

[2053] Fix output of right-stripped label sequences

Mukund Sivaraman 12 years ago
parent
commit
3a1e804a48
2 changed files with 8 additions and 8 deletions
  1. 5 5
      src/lib/dns/labelsequence.cc
  2. 3 3
      src/lib/dns/tests/labelsequence_unittest.cc

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

@@ -128,6 +128,11 @@ LabelSequence::toText(bool omit_final_dot) const {
     result.reserve(name_.getLength());
 
     while (np != np_end) {
+        if (labels == 0) {
+            count = 0;
+            break;
+        }
+
         labels--;
         count = *np++;
 
@@ -141,11 +146,6 @@ LabelSequence::toText(bool omit_final_dot) const {
             break;
         }
 
-        if (labels == 0) {
-            count = 0;
-            break;
-        }
-
         if (count <= Name::MAX_LABELLEN) {
             assert(np_end - np >= count);
 

+ 3 - 3
src/lib/dns/tests/labelsequence_unittest.cc

@@ -303,13 +303,13 @@ TEST_F(LabelSequenceTest, toText) {
 
     EXPECT_EQ("example.com.", ls2.toText());
     ls2.stripRight(1);
-    EXPECT_EQ("example", ls2.toText());
+    EXPECT_EQ("example.com", ls2.toText());
     ls2.stripRight(1);
-    EXPECT_EQ("", ls2.toText());
+    EXPECT_EQ("example", ls2.toText());
 
     EXPECT_EQ("foo.example.org.bar.", ls8.toText());
     ls8.stripRight(2);
-    EXPECT_EQ("foo.example", ls8.toText());
+    EXPECT_EQ("foo.example.org", ls8.toText());
 
     EXPECT_EQ(".", ls7.toText());
     EXPECT_THROW(ls7.stripLeft(1), isc::OutOfRange);