You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ks...@apache.org on 2021/11/04 21:33:57 UTC

[arrow] 09/18: ARROW-14514: [C++][R] UBSAN error on round kernel

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

kszucs pushed a commit to branch maint-6.0.x
in repository https://gitbox.apache.org/repos/asf/arrow.git

commit 73f85a40793348c86352ba7ae3ddebdb31a37ede
Author: Eduardo Ponce <ed...@gmail.com>
AuthorDate: Sat Oct 30 14:11:06 2021 -0400

    ARROW-14514: [C++][R] UBSAN error on round kernel
    
    Add base class `OptionsWrapper` to primary template of `RoundOptionsWrapper`.
    
    Closes #11573 from edponce/ARROW-14514-UBSAN-error-on-round-kernel
    
    Authored-by: Eduardo Ponce <ed...@gmail.com>
    Signed-off-by: David Li <li...@gmail.com>
---
 cpp/src/arrow/compute/kernels/scalar_arithmetic.cc | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/cpp/src/arrow/compute/kernels/scalar_arithmetic.cc b/cpp/src/arrow/compute/kernels/scalar_arithmetic.cc
index 48a5e81..763e40e 100644
--- a/cpp/src/arrow/compute/kernels/scalar_arithmetic.cc
+++ b/cpp/src/arrow/compute/kernels/scalar_arithmetic.cc
@@ -1048,7 +1048,7 @@ struct RoundImpl<Type, RoundMode::HALF_TO_ODD> {
 };
 
 // Specializations of kernel state for round kernels
-template <typename>
+template <typename OptionsType>
 struct RoundOptionsWrapper;
 
 template <>
@@ -1079,10 +1079,19 @@ template <>
 struct RoundOptionsWrapper<RoundToMultipleOptions>
     : public OptionsWrapper<RoundToMultipleOptions> {
   using OptionsType = RoundToMultipleOptions;
+  using State = RoundOptionsWrapper<OptionsType>;
+  using OptionsWrapper::OptionsWrapper;
 
   static Result<std::unique_ptr<KernelState>> Init(KernelContext* ctx,
                                                    const KernelInitArgs& args) {
-    ARROW_ASSIGN_OR_RAISE(auto state, OptionsWrapper<OptionsType>::Init(ctx, args));
+    std::unique_ptr<State> state;
+    if (auto options = static_cast<const OptionsType*>(args.options)) {
+      state = ::arrow::internal::make_unique<State>(*options);
+    } else {
+      return Status::Invalid(
+          "Attempted to initialize KernelState from null FunctionOptions");
+    }
+
     auto options = Get(*state);
     const auto& type = *args.inputs[0].type;
     if (!options.multiple || !options.multiple->is_valid) {