bkietz commented on code in PR #36018:
URL: https://github.com/apache/arrow/pull/36018#discussion_r1259853471


##########
cpp/src/arrow/array/data.cc:
##########
@@ -228,22 +229,20 @@ void ArraySpan::SetMembers(const ArrayData& data) {
 namespace {
 
 template <typename offset_type>
-void SetOffsetsForScalar(ArraySpan* span, offset_type* buffer, int64_t 
value_size,
-                         int buffer_index = 1) {
-  buffer[0] = 0;
-  buffer[1] = static_cast<offset_type>(value_size);
-  span->buffers[buffer_index].data = reinterpret_cast<uint8_t*>(buffer);
-  span->buffers[buffer_index].size = 2 * sizeof(offset_type);
+BufferSpan OffsetsForScalar(uint8_t* scratch_space, offset_type value_size) {
+  auto* offsets = reinterpret_cast<offset_type*>(scratch_space);
+  offsets[0] = 0;
+  offsets[1] = static_cast<offset_type>(value_size);
+  return {scratch_space, sizeof(offset_type) * 2};
 }
 
 int GetNumBuffers(const DataType& type) {
   switch (type.id()) {
     case Type::NA:
     case Type::STRUCT:
     case Type::FIXED_SIZE_LIST:
-      return 1;
     case Type::RUN_END_ENCODED:
-      return 0;
+      return 1;

Review Comment:
   Many places in the codebase assume that `buffers.size() >= 1`, even if 
`buffers[0] == nullptr`. When I added test cases which exercised REE scalars 
those places segfaulted. I thought that requiring `buffers.size() >= 1` for REE 
(as we do for union) was the most expeditious fix



-- 
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]

Reply via email to