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

yibocai 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 a788c42  ARROW-13600: [C++] Fix maybe uninitialized warnings
a788c42 is described below

commit a788c42d44a8c22b2bb271e8d7de795e93abb3ef
Author: Keith Kraus <[email protected]>
AuthorDate: Mon Aug 16 01:50:36 2021 +0000

    ARROW-13600: [C++] Fix maybe uninitialized warnings
    
    cc @michalursa to double check the changes in the hashing as that's a 
pretty performance sensitive chunk of code if I understand correctly
    
    Closes #10907 from kkraus14/fix_maybe_uninitialized
    
    Authored-by: Keith Kraus <[email protected]>
    Signed-off-by: Yibo Cai <[email protected]>
---
 cpp/src/arrow/compute/exec/key_hash.cc | 9 ++++++++-
 cpp/src/arrow/tensor.cc                | 2 +-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/cpp/src/arrow/compute/exec/key_hash.cc 
b/cpp/src/arrow/compute/exec/key_hash.cc
index 081411e..dcc42ed 100644
--- a/cpp/src/arrow/compute/exec/key_hash.cc
+++ b/cpp/src/arrow/compute/exec/key_hash.cc
@@ -198,8 +198,15 @@ void Hashing::hash_varlen_helper(uint32_t length, const 
uint8_t* key, uint32_t*
       last_stripe[1] = last_stripe_base[1];
       last_stripe[1] &= mask;
     }
+
+    // The stack allocation and memcpy here should be optimized out by the 
compiler.
+    // Using a reinterpret_cast causes a compiler warning on gcc and can lead 
to incorrect
+    // results. See https://issues.apache.org/jira/browse/ARROW-13600 for more 
info.
+    uint32_t lanes[4];
+    memcpy(&lanes, &last_stripe, sizeof(last_stripe));
+
     for (int j = 0; j < 4; ++j) {
-      uint32_t lane = reinterpret_cast<const uint32_t*>(last_stripe)[j];
+      uint32_t lane = lanes[j];
       acc[j] += (lane * PRIME32_2);
       acc[j] = ROTL(acc[j], 13);
       acc[j] *= PRIME32_1;
diff --git a/cpp/src/arrow/tensor.cc b/cpp/src/arrow/tensor.cc
index d591bac..30ae8c4 100644
--- a/cpp/src/arrow/tensor.cc
+++ b/cpp/src/arrow/tensor.cc
@@ -328,7 +328,7 @@ struct NonZeroCounter {
   }
 
   const Tensor& tensor_;
-  int64_t result;
+  int64_t result = 0;
 };
 
 }  // namespace

Reply via email to