From b6858622ebca63f16e91cbb289ec36317f1edb92 Mon Sep 17 00:00:00 2001 From: Alexander Mai Date: Sat, 20 Jun 2015 23:15:35 +0200 Subject: [PATCH] #6779 internal error: division overflow. Previous error handling (see #4520) was too restrictive. --- lib/mathlib.cpp | 4 ++-- test/testmathlib.cpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/mathlib.cpp b/lib/mathlib.cpp index 834fb7c64..a6910f02c 100644 --- a/lib/mathlib.cpp +++ b/lib/mathlib.cpp @@ -617,10 +617,10 @@ std::string MathLib::divide(const std::string &first, const std::string &second) if (MathLib::isInt(first) && MathLib::isInt(second)) { const bigint a = toLongNumber(first); const bigint b = toLongNumber(second); - if (a == std::numeric_limits::min()) - throw InternalError(0, "Internal Error: Division overflow"); if (b == 0) throw InternalError(0, "Internal Error: Division by zero"); + if (a == std::numeric_limits::min() && std::abs(b)<=1) + throw InternalError(0, "Internal Error: Division overflow"); return toString(toLongNumber(first) / b) + intsuffix(first, second); } else if (isNullValue(second)) { if (isNullValue(first)) diff --git a/test/testmathlib.cpp b/test/testmathlib.cpp index b09f81132..98f340ee5 100644 --- a/test/testmathlib.cpp +++ b/test/testmathlib.cpp @@ -139,6 +139,7 @@ private: ASSERT_EQUALS("1" , MathLib::divide("3", "2")); ASSERT_THROW(MathLib::divide("123", "0"), InternalError); // throw ASSERT_THROW(MathLib::divide("-9223372036854775808", "-1"), InternalError); // #4520 - out of range => throw + ASSERT_EQUALS("4611686018427387904", MathLib::divide("-9223372036854775808", "-2")); // #6679 MathLib::divide("123", "0.0"); // don't throw // Unknown action should throw exception