You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by ta...@apache.org on 2020/03/03 17:16:28 UTC

[impala] 03/05: IMPALA-9447: Fix for TupleRowCompareTest.DecimalTest crash

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

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

commit d448f465091455082e9e71020f860edbb4465ba9
Author: norbert.luksa <no...@cloudera.com>
AuthorDate: Tue Mar 3 09:51:28 2020 +0100

    IMPALA-9447: Fix for TupleRowCompareTest.DecimalTest crash
    
    TupleRowCompareTest.DecimalTest crashes on release build
    because of a faulty test. The problem occures with Decimal16Value
    when the test tries to copy the values into the tuple in FillMem().
    
    The solution is to use memcpy to avoid gcc generating unaligned
    instructions like movaps for int128_t. They would raise SegmentFault
    when addresses are not aligned to 16 bytes. This works with the
    other types as well.
    
    Tests:
     - Run TupleRowCompareTest.
    
    Change-Id: If2a53c88b57cec3a0bfcf02c492fbb560a80682d
    Reviewed-on: http://gerrit.cloudera.org:8080/15347
    Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
    Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
 be/src/util/tuple-row-compare-test.cc | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/be/src/util/tuple-row-compare-test.cc b/be/src/util/tuple-row-compare-test.cc
index 2c1b196..929d525 100644
--- a/be/src/util/tuple-row-compare-test.cc
+++ b/be/src/util/tuple-row-compare-test.cc
@@ -113,12 +113,15 @@ class TupleRowCompareTest : public testing::Test {
 
   template <typename T>
   void FillMem(Tuple* tuple_mem, int idx, T val) {
-    *reinterpret_cast<T*>(tuple_mem->GetSlot(idx)) = val;
+    memcpy(tuple_mem->GetSlot(idx), &val, sizeof(T));
   }
 
   template <typename T, typename... Args>
   void FillMem(Tuple* tuple_mem, int idx, T val, Args... args) {
-    *reinterpret_cast<T*>(tuple_mem->GetSlot(idx)) = val;
+    // Use memcpy to avoid gcc generating unaligned instructions like movaps
+    // for int128_t. They will raise SegmentFault when addresses are not
+    // aligned to 16 bytes.
+    memcpy(tuple_mem->GetSlot(idx), &val, sizeof(T));
     FillMem(tuple_mem, idx + sizeof(T), args...);
   }
 
@@ -233,10 +236,12 @@ class TupleRowCompareTest : public testing::Test {
     ColumnType decimal_column = ColumnType::CreateDecimalType(precision, scale);
     CreateComperator(decimal_column, decimal_column);
     bool overflow = false;
-    TupleRow* lhs = CreateTupleRow(DECIMAL_T::FromInt(precision, scale, lval1, &overflow),
-        DECIMAL_T::FromInt(precision, scale, lval2, &overflow));
-    TupleRow* rhs = CreateTupleRow(DECIMAL_T::FromInt(precision, scale, rval1, &overflow),
-        DECIMAL_T::FromInt(precision, scale, rval2, &overflow));
+    DECIMAL_T l1 = DECIMAL_T::FromInt(precision, scale, lval1, &overflow);
+    DECIMAL_T l2 = DECIMAL_T::FromInt(precision, scale, lval2, &overflow);
+    DECIMAL_T r1 = DECIMAL_T::FromInt(precision, scale, rval1, &overflow);
+    DECIMAL_T r2 = DECIMAL_T::FromInt(precision, scale, rval2, &overflow);
+    TupleRow* lhs = CreateTupleRow(l1, l2);
+    TupleRow* rhs = CreateTupleRow(r1, r2);
     int result = comperator_->Compare(lhs, rhs);
     comperator_->Close(runtime_state_);
     return result;