Copilot commented on code in PR #55439:
URL: https://github.com/apache/arrow/pull/55439#discussion_r4584990162
##########
cpp/src/arrow/buffer.h:
##########
@@ -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);
Review Comment:
This change avoids UB for null-backed CPU buffers, but it can also
unintentionally drop a non-zero logical address when `parent` is
non-CPU/device-backed (where `data_` may be null while an address is still
meaningful). In that case, the sliced buffer would be constructed with
`nullptr` and can lose the correct offset address. Consider basing slicing on
the parent's logical address (or an existing device-safe accessor/constructor)
and only deriving `data_` when the parent is CPU-backed, so device buffers
preserve their address semantics while still avoiding null pointer arithmetic.
##########
cpp/src/arrow/buffer.cc:
##########
@@ -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,
Review Comment:
`parent->mutable_address()` is evaluated twice in the conditional
expression. Storing it in a local (e.g., `const auto base =
parent->mutable_address();`) would avoid duplicate calls and make the intent
clearer (especially if `mutable_address()` is non-trivial on some buffer
implementations).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]