Skip to content

Commit 8d06d09

Browse files
committed
Fix broken ByteBuffer copy ctor
1 parent 18ce0cf commit 8d06d09

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Diff for: src/cpp/util/byte_buffer_cc.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ Status ByteBuffer::Dump(std::vector<Slice>* slices) const {
4343
return Status::OK;
4444
}
4545

46-
ByteBuffer::ByteBuffer(const ByteBuffer& buf)
47-
: buffer_(grpc_byte_buffer_copy(buf.buffer_)) {}
46+
ByteBuffer::ByteBuffer(const ByteBuffer& buf) : buffer_(nullptr) {
47+
operator=(buf);
48+
}
4849

4950
ByteBuffer& ByteBuffer::operator=(const ByteBuffer& buf) {
5051
if (this != &buf) {

Diff for: test/cpp/util/byte_buffer_test.cc

+7
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ const char* kContent2 = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy world";
3838

3939
class ByteBufferTest : public ::testing::Test {};
4040

41+
TEST_F(ByteBufferTest, CopyCtor) {
42+
ByteBuffer buffer1;
43+
EXPECT_FALSE(buffer1.Valid());
44+
ByteBuffer buffer2 = buffer1;
45+
EXPECT_FALSE(buffer2.Valid());
46+
}
47+
4148
TEST_F(ByteBufferTest, CreateFromSingleSlice) {
4249
Slice s(kContent1);
4350
ByteBuffer buffer(&s, 1);

0 commit comments

Comments
 (0)