Merge pull request #15517 from ara-ayvazyan/fix_bytebuffer_copy_ctor

Fix broken ByteBuffer copy ctor
pull/15541/head
Noah Eisen 7 years ago committed by GitHub
commit 628073d4c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      src/cpp/util/byte_buffer_cc.cc
  2. 7
      test/cpp/util/byte_buffer_test.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) {

@ -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);

Loading…
Cancel
Save