aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Ara Ayvazyan <Aivazyan@microsoft.com>2018-05-22 20:47:35 -0700
committerGravatar Ara Ayvazyan <Aivazyan@microsoft.com>2018-05-22 20:47:35 -0700
commit8d06d097bc313eb8483bddfe716ccf39c50366f5 (patch)
tree630850625cdb48e52ff911e537a53baab40632d3
parent18ce0cf26e733647b33cbaafee57245fdfb932e7 (diff)
Fix broken ByteBuffer copy ctor
-rw-r--r--src/cpp/util/byte_buffer_cc.cc5
-rw-r--r--test/cpp/util/byte_buffer_test.cc7
2 files changed, 10 insertions, 2 deletions
diff --git a/src/cpp/util/byte_buffer_cc.cc b/src/cpp/util/byte_buffer_cc.cc
index 8700f96d8d..a7e1645435 100644
--- a/src/cpp/util/byte_buffer_cc.cc
+++ b/src/cpp/util/byte_buffer_cc.cc
@@ -43,8 +43,9 @@ Status ByteBuffer::Dump(std::vector<Slice>* slices) const {
return Status::OK;
}
-ByteBuffer::ByteBuffer(const ByteBuffer& buf)
- : buffer_(grpc_byte_buffer_copy(buf.buffer_)) {}
+ByteBuffer::ByteBuffer(const ByteBuffer& buf) : buffer_(nullptr) {
+ operator=(buf);
+}
ByteBuffer& ByteBuffer::operator=(const ByteBuffer& buf) {
if (this != &buf) {
diff --git a/test/cpp/util/byte_buffer_test.cc b/test/cpp/util/byte_buffer_test.cc
index 47a5b7f03a..b48a53eed1 100644
--- a/test/cpp/util/byte_buffer_test.cc
+++ b/test/cpp/util/byte_buffer_test.cc
@@ -38,6 +38,13 @@ const char* kContent2 = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy world";
class ByteBufferTest : public ::testing::Test {};
+TEST_F(ByteBufferTest, CopyCtor) {
+ ByteBuffer buffer1;
+ EXPECT_FALSE(buffer1.Valid());
+ ByteBuffer buffer2 = buffer1;
+ EXPECT_FALSE(buffer2.Valid());
+}
+
TEST_F(ByteBufferTest, CreateFromSingleSlice) {
Slice s(kContent1);
ByteBuffer buffer(&s, 1);