Suppress UBSan report in Decimal comparison

This commit is contained in:
Alexey Milovidov 2021-02-13 03:54:38 +03:00
parent 54554247bf
commit 1546f5bcb9
4 changed files with 15 additions and 3 deletions

View File

@ -156,4 +156,11 @@ namespace common
return false;
return (x * y) / y != x;
}
/// Multiply and ignore overflow.
template <typename T1, typename T2>
inline auto NO_SANITIZE_UNDEFINED mulIgnoreOverflow(T1 x, T2 y)
{
return x * y;
}
}

View File

@ -21,7 +21,7 @@ namespace ErrorCodes
extern const int DECIMAL_OVERFLOW;
}
///
inline bool allowDecimalComparison(const DataTypePtr & left_type, const DataTypePtr & right_type)
{
if (isColumnedAsDecimal(left_type))
@ -30,7 +30,9 @@ inline bool allowDecimalComparison(const DataTypePtr & left_type, const DataType
return true;
}
else if (isNotDecimalButComparableToDecimal(left_type) && isColumnedAsDecimal(right_type))
{
return true;
}
return false;
}
@ -252,9 +254,9 @@ private:
else
{
if constexpr (scale_left)
x *= scale;
x = common::mulIgnoreOverflow(x, scale);
if constexpr (scale_right)
y *= scale;
y = common::mulIgnoreOverflow(y, scale);
}
return Op::apply(x, y);

View File

@ -0,0 +1,2 @@
SET decimal_check_overflow = 0;
SELECT toDecimal64(0, 8) = 9223372036854775807;