You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ko...@apache.org on 2020/06/14 05:01:12 UTC

[arrow] branch master updated: ARROW-9116: [C++][FOLLOWUP] Add 0-length test for BaseBinaryArray::total_values_length

This is an automated email from the ASF dual-hosted git repository.

kou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new 3ccecfb  ARROW-9116: [C++][FOLLOWUP] Add 0-length test for BaseBinaryArray::total_values_length
3ccecfb is described below

commit 3ccecfb369aeb3a84aec4efbd7da42ea17282726
Author: Wes McKinney <we...@apache.org>
AuthorDate: Sun Jun 14 14:00:32 2020 +0900

    ARROW-9116: [C++][FOLLOWUP] Add 0-length test for BaseBinaryArray::total_values_length
    
    This also protects against the offsets buffer being null.
    
    Closes #7431 from wesm/ARROW-9116-followup
    
    Authored-by: Wes McKinney <we...@apache.org>
    Signed-off-by: Sutou Kouhei <ko...@clear-code.com>
---
 cpp/src/arrow/array/array_binary.h       | 8 ++++++--
 cpp/src/arrow/array/array_binary_test.cc | 5 +++++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/cpp/src/arrow/array/array_binary.h b/cpp/src/arrow/array/array_binary.h
index e27a2bf..b291de3 100644
--- a/cpp/src/arrow/array/array_binary.h
+++ b/cpp/src/arrow/array/array_binary.h
@@ -105,8 +105,12 @@ class BaseBinaryArray : public FlatArray {
   /// referenced by this array. If the array has been sliced then this may be
   /// less than the size of the data buffer (data_->buffers[2]).
   offset_type total_values_length() const {
-    return raw_value_offsets_[data_->length + data_->offset] -
-           raw_value_offsets_[data_->offset];
+    if (data_->length > 0) {
+      return raw_value_offsets_[data_->length + data_->offset] -
+             raw_value_offsets_[data_->offset];
+    } else {
+      return 0;
+    }
   }
 
  protected:
diff --git a/cpp/src/arrow/array/array_binary_test.cc b/cpp/src/arrow/array/array_binary_test.cc
index 41945e5..f20f0ea 100644
--- a/cpp/src/arrow/array/array_binary_test.cc
+++ b/cpp/src/arrow/array/array_binary_test.cc
@@ -119,6 +119,11 @@ class TestStringArray : public ::testing::Test {
     offset_type sliced_values_length =
         checked_cast<const ArrayType&>(*arr.Slice(3)).total_values_length();
     ASSERT_EQ(sliced_values_length, static_cast<offset_type>(9));
+
+    // Zero-length array is a special case
+    offset_type zero_size_length =
+        checked_cast<const ArrayType&>(*arr.Slice(0, 0)).total_values_length();
+    ASSERT_EQ(zero_size_length, static_cast<offset_type>(0));
   }
 
   void TestType() {