diff --git a/src/Functions/FunctionsDecimalArithmetics.h b/src/Functions/FunctionsDecimalArithmetics.h index d911b9cd350..38f26f5ff6b 100644 --- a/src/Functions/FunctionsDecimalArithmetics.h +++ b/src/Functions/FunctionsDecimalArithmetics.h @@ -153,7 +153,7 @@ struct DivideDecimalsImpl ++scale_a; } - while (scale_a > scale_b + result_scale && a_digits.size()) + while (scale_a > scale_b + result_scale && !a_digits.empty()) { a_digits.pop_back(); --scale_a; @@ -196,12 +196,15 @@ struct MultiplyDecimalsImpl ++product_scale; } - while (product_scale > result_scale) + while (product_scale > result_scale&& !multiplied.empty()) { multiplied.pop_back(); --product_scale; } + if (multiplied.empty()) + return Decimal256(0); + if (multiplied.size() > 76) throw DB::Exception("Numeric overflow: result bigger that Decimal256", ErrorCodes::DECIMAL_OVERFLOW);