diff options
-rw-r--r-- | src/mongo/base/data_builder.h | 5 | ||||
-rw-r--r-- | src/mongo/base/data_builder_test.cpp | 4 |
2 files changed, 6 insertions, 3 deletions
diff --git a/src/mongo/base/data_builder.h b/src/mongo/base/data_builder.h index 92a0ba73d0a..aa7cb29154b 100644 --- a/src/mongo/base/data_builder.h +++ b/src/mongo/base/data_builder.h @@ -78,9 +78,12 @@ public: } DataBuilder& operator=(DataBuilder&& other) { + size_t size = other.size(); _buf = std::move(other._buf); _capacity = other._capacity; - _unwrittenSpaceCursor = {_buf.get(), _buf.get() + other.size()}; + char* start = _buf.get() + size; + char* end = _buf.get() + _capacity; + _unwrittenSpaceCursor = {start, end}; other._capacity = 0; other._unwrittenSpaceCursor = {nullptr, nullptr}; diff --git a/src/mongo/base/data_builder_test.cpp b/src/mongo/base/data_builder_test.cpp index ed001bd31b1..0133ae20273 100644 --- a/src/mongo/base/data_builder_test.cpp +++ b/src/mongo/base/data_builder_test.cpp @@ -151,7 +151,7 @@ TEST(DataBuilder, Clear) { } TEST(DataBuilder, Move) { - DataBuilder db(1); + DataBuilder db(42); ASSERT_EQUALS(true, db.writeAndAdvance<uint16_t>(1).isOK()); @@ -160,7 +160,7 @@ TEST(DataBuilder, Move) { ConstDataRangeCursor cdrc = db2.getCursor(); ASSERT_EQUALS(static_cast<uint16_t>(1), cdrc.readAndAdvance<uint16_t>()); - ASSERT_EQUALS(2u, db2.capacity()); + ASSERT_EQUALS(42u, db2.capacity()); ASSERT_EQUALS(2u, db2.size()); ASSERT_EQUALS(0u, db.capacity()); |