Repository: impala
Updated Branches:
refs/heads/master 153663c22 -> 2a4835cfb
IMPALA-5031: signed overflow is undefined behavior
This patch fixes a signed overflow in the backend test
DecimalTest.Overflow. The interesting part of the backtrace is:
runtime/decimal-value.inline.h:254:17: runtime error: signed integer
overflow: 0x4b3b4ca85a86c47a098a223fffffffff +
0x4b3b4ca85a86c47a098a223fffffffff cannot be represented in
type '__int128'
#0 detail::AddLarge(__int128, int, __int128, int, int, bool,
bool*) runtime/decimal-value.inline.h:254:17
#1 DecimalValue<__int128> DecimalValue<__int128>::Add<__int128>(
int, DecimalValue<__int128> const&, int, int, int, bool,
bool*) const runtime/decimal-value.inline.h:371:14
#2 DecimalTest_Overflow_Test::TestBody()
runtime/decimal-test.cc:540:9
Change-Id: I146bcf35d34cc0e14be0633427d3e4bd0e5a261e
Reviewed-on: http://gerrit.cloudera.org:8080/11917
Reviewed-by: Jim Apple <[email protected]>
Tested-by: Impala Public Jenkins <[email protected]>
Project: http://git-wip-us.apache.org/repos/asf/impala/repo
Commit: http://git-wip-us.apache.org/repos/asf/impala/commit/53ce6bb5
Tree: http://git-wip-us.apache.org/repos/asf/impala/tree/53ce6bb5
Diff: http://git-wip-us.apache.org/repos/asf/impala/diff/53ce6bb5
Branch: refs/heads/master
Commit: 53ce6bb571cd9ae07ba5255197d35aa852a6f97c
Parents: 153663c
Author: Jim Apple <[email protected]>
Authored: Fri Nov 9 09:37:00 2018 -0800
Committer: Impala Public Jenkins <[email protected]>
Committed: Sun Nov 18 06:50:50 2018 +0000
----------------------------------------------------------------------
be/src/runtime/decimal-value.inline.h | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/impala/blob/53ce6bb5/be/src/runtime/decimal-value.inline.h
----------------------------------------------------------------------
diff --git a/be/src/runtime/decimal-value.inline.h
b/be/src/runtime/decimal-value.inline.h
index 3150aef..cb889e6 100644
--- a/be/src/runtime/decimal-value.inline.h
+++ b/be/src/runtime/decimal-value.inline.h
@@ -28,6 +28,7 @@
#include <sstream>
#include "common/logging.h"
+#include "util/arithmetic-util.h"
#include "util/bit-util.h"
#include "util/decimal-util.h"
#include "util/hash-util.h"
@@ -251,7 +252,9 @@ inline int128_t AddLarge(int128_t x, int x_scale, int128_t
y, int y_scale,
DCHECK(right <= DecimalUtil::GetScaleMultiplier<int128_t>(result_scale));
*overflow |= x_left > DecimalUtil::MAX_UNSCALED_DECIMAL16 - y_left -
carry_to_left;
- left = x_left + y_left + carry_to_left;
+ left = ArithmeticUtil::AsUnsigned<std::plus>(
+ ArithmeticUtil::AsUnsigned<std::plus>(x_left, y_left),
+ static_cast<int128_t>(carry_to_left));
int128_t mult = DecimalUtil::GetScaleMultiplier<int128_t>(result_scale);
if (UNLIKELY(!*overflow &&