Repository: incubator-impala Updated Branches: refs/heads/master 874d20d0f -> 23100102c
IMPALA-5031: Remove undefined behavior: left shift of negative values Left shift of negative values is undefined According to C++14 section 5.8 [expr.shift], paragraph 2. Change-Id: I9d965c3950a878c0a41b374d51bbe2e5705b3360 Reviewed-on: http://gerrit.cloudera.org:8080/6491 Reviewed-by: Dan Hecht <[email protected]> Reviewed-by: Tim Armstrong <[email protected]> Tested-by: Impala Public Jenkins Project: http://git-wip-us.apache.org/repos/asf/incubator-impala/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-impala/commit/4aa8e2d5 Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/4aa8e2d5 Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/4aa8e2d5 Branch: refs/heads/master Commit: 4aa8e2d5cf590d6366a600f15bed3e998ccc4031 Parents: 874d20d Author: Jim Apple <[email protected]> Authored: Sat Mar 25 13:35:19 2017 -0700 Committer: Impala Public Jenkins <[email protected]> Committed: Tue Mar 28 22:16:25 2017 +0000 ---------------------------------------------------------------------- be/src/exec/read-write-util.cc | 4 ++-- be/src/exec/zigzag-test.cc | 2 +- be/src/exprs/bit-byte-functions-ir.cc | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/4aa8e2d5/be/src/exec/read-write-util.cc ---------------------------------------------------------------------- diff --git a/be/src/exec/read-write-util.cc b/be/src/exec/read-write-util.cc index 1ae98c3..ef9f412 100644 --- a/be/src/exec/read-write-util.cc +++ b/be/src/exec/read-write-util.cc @@ -93,7 +93,7 @@ ReadWriteUtil::ReadZInteger<ReadWriteUtil::MAX_ZINT_LEN, ReadWriteUtil::ZIntResu int ReadWriteUtil::PutZInt(int32_t integer, uint8_t* buf) { // Move the sign bit to the first bit. - uint32_t uinteger = (integer << 1) ^ (integer >> 31); + uint32_t uinteger = (static_cast<uint32_t>(integer) << 1) ^ (integer >> 31); const int mask = 0x7f; const int cont = 0x80; buf[0] = uinteger & mask; @@ -110,7 +110,7 @@ int ReadWriteUtil::PutZInt(int32_t integer, uint8_t* buf) { int ReadWriteUtil::PutZLong(int64_t longint, uint8_t* buf) { // Move the sign bit to the first bit. - uint64_t ulongint = (longint << 1) ^ (longint >> 63); + uint64_t ulongint = (static_cast<uint64_t>(longint) << 1) ^ (longint >> 63); const int mask = 0x7f; const int cont = 0x80; buf[0] = ulongint & mask; http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/4aa8e2d5/be/src/exec/zigzag-test.cc ---------------------------------------------------------------------- diff --git a/be/src/exec/zigzag-test.cc b/be/src/exec/zigzag-test.cc index 87b686c..ea9363f 100644 --- a/be/src/exec/zigzag-test.cc +++ b/be/src/exec/zigzag-test.cc @@ -98,7 +98,7 @@ TEST(ZigzagTest, Basic) { value = HashUtil::Hash(&value, sizeof (value), i); TestZInt(value); TestZLong(value); - TestZLong((static_cast<int64_t>(value) << 32) | value); + TestZLong((static_cast<uint64_t>(value) << 32) | value); } } http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/4aa8e2d5/be/src/exprs/bit-byte-functions-ir.cc ---------------------------------------------------------------------- diff --git a/be/src/exprs/bit-byte-functions-ir.cc b/be/src/exprs/bit-byte-functions-ir.cc index c2208ad..3464174 100644 --- a/be/src/exprs/bit-byte-functions-ir.cc +++ b/be/src/exprs/bit-byte-functions-ir.cc @@ -158,7 +158,9 @@ static T RotateRightImpl(T v, int32_t shift) { // Handle wrapping around multiple times shift = shift % (sizeof(T) * 8); - return BitUtil::ShiftRightLogical(v, shift) | (v << (sizeof(T) * 8 - shift)); + using UnsignedT = std::make_unsigned_t<T>; + return BitUtil::ShiftRightLogical(v, shift) + | (static_cast<UnsignedT>(v) << (sizeof(T) * 8 - shift)); } template<typename T>
