diff --git a/cpp/src/arrow/types/primitive.h b/cpp/src/arrow/types/primitive.h index 1073bb6e1c340..22ab59c309a1d 100644 --- a/cpp/src/arrow/types/primitive.h +++ b/cpp/src/arrow/types/primitive.h @@ -168,7 +168,9 @@ class PrimitiveBuilder : public ArrayBuilder { int32_t new_capacity = util::next_power2(length_ + length); RETURN_NOT_OK(Resize(new_capacity)); } - memcpy(raw_buffer() + length_, values, length * elsize_); + if (length > 0) { + memcpy(raw_buffer() + length_, values, length * elsize_); + } if (null_bytes != nullptr) { AppendNulls(null_bytes, length); diff --git a/cpp/src/arrow/types/string-test.cc b/cpp/src/arrow/types/string-test.cc index 8e82fd95dd808..6381093dcbb45 100644 --- a/cpp/src/arrow/types/string-test.cc +++ b/cpp/src/arrow/types/string-test.cc @@ -181,7 +181,7 @@ class TestStringBuilder : public TestBuilder { }; TEST_F(TestStringBuilder, TestScalarAppend) { - std::vector strings = {"a", "bb", "", "", "ccc"}; + std::vector strings = {"", "bb", "a", "", "ccc"}; std::vector is_null = {0, 0, 0, 1, 0}; int N = strings.size(); diff --git a/python/pyarrow/tests/test_array.py b/python/pyarrow/tests/test_array.py index 034c1576551d3..36aaaa4f93d5d 100644 --- a/python/pyarrow/tests/test_array.py +++ b/python/pyarrow/tests/test_array.py @@ -39,13 +39,13 @@ def test_list_format(self): assert result == expected def test_string_format(self): - arr = pyarrow.from_pylist(['foo', None, 'bar']) + arr = pyarrow.from_pylist(['', None, 'foo']) result = fmt.array_format(arr) expected = """\ [ - 'foo', + '', NA, - 'bar' + 'foo' ]""" assert result == expected