Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cpp/src/arrow/buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ std::shared_ptr<Buffer> SliceMutableBuffer(std::shared_ptr<Buffer> buffer,

MutableBuffer::MutableBuffer(const std::shared_ptr<Buffer>& parent, const int64_t offset,
const int64_t size)
: MutableBuffer(reinterpret_cast<uint8_t*>(parent->mutable_address()) + offset,
: MutableBuffer(parent->mutable_address()
? reinterpret_cast<uint8_t*>(parent->mutable_address() + offset)
: nullptr,
size) {
DCHECK(parent->is_mutable()) << "Must pass mutable buffer";
parent_ = parent;
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class ARROW_EXPORT Buffer {
/// in general we expected buffers to be aligned and padded to 64 bytes. In the future
/// we might add utility methods to help determine if a buffer satisfies this contract.
Buffer(std::shared_ptr<Buffer> parent, const int64_t offset, const int64_t size)
: Buffer(parent->data_ + offset, size) {
: Buffer(parent->data_ ? parent->data_ + offset : nullptr, size) {
parent_ = std::move(parent);
SetMemoryManager(parent_->memory_manager_);
}
Expand Down
12 changes: 12 additions & 0 deletions cpp/src/arrow/buffer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,18 @@ TEST(TestBuffer, ToHexString) {
ASSERT_EQ(buf.ToHexString(), std::string("073068657820737472696E67A9"));
}

TEST(TestBuffer, SliceNullBuffer) {
auto null_buffer = std::make_shared<Buffer>(nullptr, 16);
auto sliced = SliceBuffer(null_buffer, 8, 8);
EXPECT_EQ(sliced->data(), nullptr);
EXPECT_EQ(sliced->size(), 8);

auto null_mutable = std::make_shared<MutableBuffer>(nullptr, 16);
auto sliced_mutable = SliceMutableBuffer(null_mutable, 8, 8);
EXPECT_EQ(sliced_mutable->mutable_data(), nullptr);
EXPECT_EQ(sliced_mutable->size(), 8);
}

TEST(TestBuffer, SliceBuffer) {
std::string data_str = "some data to slice";
auto data = reinterpret_cast<const uint8_t*>(data_str.c_str());
Expand Down
Loading