Browse Source

[2369] Fix vector::erase() call in InputSource

The single-argument variant of vector::erase() deletes just one element
of the vector, not an entire range.  Tests have been fixed to check
that the range from start to the current buffer position is dropped
correctly.
Mukund Sivaraman 12 years ago
parent
commit
ba71154440
2 changed files with 8 additions and 3 deletions
  1. 1 1
      src/lib/dns/inputsource.cc
  2. 7 2
      src/lib/dns/tests/inputsource_unittest.cc

+ 1 - 1
src/lib/dns/inputsource.cc

@@ -107,7 +107,7 @@ InputSource::compact() {
     if (buffer_pos_ == buffer_.size()) {
         buffer_.clear();
     } else {
-        buffer_.erase(buffer_.begin() + buffer_pos_);
+        buffer_.erase(buffer_.begin(), buffer_.begin() + buffer_pos_);
     }
 
     buffer_pos_ = 0;

+ 7 - 2
src/lib/dns/tests/inputsource_unittest.cc

@@ -172,13 +172,18 @@ TEST_F(InputSourceTest, compactDuring) {
     size_t line = source_.getCurrentLine();
     EXPECT_EQ(2, line);
 
+    // Now, unget a couple of characters. This should cause the
+    // buffer_pos_ to be not equal to the size of the buffer.
+    source_.ungetChar();
+    source_.ungetChar();
+
     source_.saveLine();
     source_.compact();
 
     // Ungetting here must throw.
     EXPECT_THROW(source_.ungetChar(), InputSource::UngetError);
 
-    for (size_t i = 15; i < str_length_; i++) {
+    for (size_t i = 13; i < str_length_; i++) {
         EXPECT_EQ(str_[i], source_.getChar());
         EXPECT_FALSE(source_.atEOF());
     }
@@ -198,7 +203,7 @@ TEST_F(InputSourceTest, compactDuring) {
     // Ungetting here must throw.
     EXPECT_THROW(source_.ungetChar(), InputSource::UngetError);
 
-    for (size_t i = 15; i < str_length_; i++) {
+    for (size_t i = 13; i < str_length_; i++) {
         EXPECT_EQ(str_[i], source_.getChar());
         EXPECT_FALSE(source_.atEOF());
     }