From d5c9c14f636cbf4451af9ad6a29045415fc3d7de Mon Sep 17 00:00:00 2001 From: Benjamin Kietzman Date: Wed, 22 May 2019 11:06:26 -0400 Subject: [PATCH] use checked_cast --- cpp/src/arrow/compute/kernels/mask.cc | 10 ++++++---- cpp/src/arrow/compute/kernels/take.cc | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/cpp/src/arrow/compute/kernels/mask.cc b/cpp/src/arrow/compute/kernels/mask.cc index 472c50af9dfa1..2aaa9a9a622e1 100644 --- a/cpp/src/arrow/compute/kernels/mask.cc +++ b/cpp/src/arrow/compute/kernels/mask.cc @@ -30,6 +30,8 @@ namespace arrow { namespace compute { +using internal::checked_cast; + Status Mask(FunctionContext* context, const Array& values, const Array& mask, std::shared_ptr* out) { Datum out_datum; @@ -135,18 +137,18 @@ struct UnpackValues { template Status Visit(const ValueType&) { using OutBuilder = typename TypeTraits::BuilderType; - auto&& mask = static_cast&>(*params_.mask); - auto&& values = static_cast&>(*params_.values); + const auto& mask = checked_cast&>(*params_.mask); + const auto& values = checked_cast&>(*params_.values); std::unique_ptr builder; RETURN_NOT_OK(MakeBuilder(params_.context->memory_pool(), values.type(), &builder)); RETURN_NOT_OK(builder->Reserve(OutputSize(mask))); RETURN_NOT_OK(UnpackValuesNullCount(params_.context, values, mask, - static_cast(builder.get()))); + checked_cast(builder.get()))); return builder->Finish(params_.out); } Status Visit(const NullType& t) { - auto&& mask = static_cast&>(*params_.mask); + const auto& mask = checked_cast&>(*params_.mask); params_.out->reset(new NullArray(OutputSize(mask))); return Status::OK(); } diff --git a/cpp/src/arrow/compute/kernels/take.cc b/cpp/src/arrow/compute/kernels/take.cc index 6addcd7444ded..b77715abb6ffc 100644 --- a/cpp/src/arrow/compute/kernels/take.cc +++ b/cpp/src/arrow/compute/kernels/take.cc @@ -28,6 +28,8 @@ namespace arrow { namespace compute { +using internal::checked_cast; + Status Take(FunctionContext* context, const Array& values, const Array& indices, std::shared_ptr* out) { Datum out_datum; @@ -117,20 +119,20 @@ struct UnpackValues { Status Visit(const ValueType&) { using ValueArrayRef = const typename TypeTraits::ArrayType&; using OutBuilder = typename TypeTraits::BuilderType; - IndexArrayRef indices = static_cast(*params_.indices); - ValueArrayRef values = static_cast(*params_.values); + IndexArrayRef indices = checked_cast(*params_.indices); + ValueArrayRef values = checked_cast(*params_.values); std::unique_ptr builder; RETURN_NOT_OK(MakeBuilder(params_.context->memory_pool(), values.type(), &builder)); RETURN_NOT_OK(builder->Reserve(indices.length())); RETURN_NOT_OK(UnpackValuesNullCount(params_.context, values, indices, - static_cast(builder.get()))); + checked_cast(builder.get()))); return builder->Finish(params_.out); } Status Visit(const NullType& t) { auto indices_length = params_.indices->length(); if (indices_length != 0) { - auto indices = static_cast(*params_.indices).raw_values(); + auto indices = checked_cast(*params_.indices).raw_values(); auto minmax = std::minmax_element(indices, indices + indices_length); auto min = static_cast(*minmax.first); auto max = static_cast(*minmax.second);