Skip to content

Commit

Permalink
apacheGH-36913: [C++] Skip empty buffer concatenation to fix UBSan error
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ebrossard committed Jul 27, 2023
1 parent 0f29147 commit 6d25184
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cpp/src/arrow/buffer.cc
Expand Up @@ -213,8 +213,11 @@ Result<std::shared_ptr<Buffer>> ConcatenateBuffers(
ARROW_ASSIGN_OR_RAISE(auto out, AllocateBuffer(out_length, pool));
auto out_data = out->mutable_data();
for (const auto& buffer : buffers) {
std::memcpy(out_data, buffer->data(), buffer->size());
out_data += buffer->size();
// Passing nullptr to std::memcpy is undefined behavior, so skip empty buffers
if (buffer->size() != 0) {
std::memcpy(out_data, buffer->data(), buffer->size());
out_data += buffer->size();
}
}
return std::move(out);
}
Expand Down

0 comments on commit 6d25184

Please sign in to comment.