summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Benvenuto <mark.benvenuto@mongodb.com>2019-10-23 22:44:55 +0000
committerevergreen <evergreen@mongodb.com>2019-10-23 22:44:55 +0000
commit4cf93b3802fa90ba02cdeed36b4f6d615b6d6393 (patch)
tree49e1f8fa03115533f8971c9f0321b47de8b95353
parentfcff61405cffec61340caf4090615317b5ac5991 (diff)
downloadmongo-4cf93b3802fa90ba02cdeed36b4f6d615b6d6393.tar.gz
SERVER-44132 DataBuilder move assignment computes size incorrectly
-rw-r--r--src/mongo/base/data_builder.h5
-rw-r--r--src/mongo/base/data_builder_test.cpp4
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());