Commit b514a5f9 authored by Alexander Barkov's avatar Alexander Barkov

A cleanup for MDEV-17249 MAKETIME(-1e50,0,0) returns a wrong result

Unary minus operation for the smallest possible signed long long value
(LONLONG_MIN) is undefined in C++. Because of this, func_time.test
failed on ppc64 buildbot machines.

Fixing the code to avod using undefined operations.

This is fix is similar to "MDEV-7973 bigint fail with gcc 5.0"
parent 948e8880
......@@ -33,7 +33,11 @@ class Longlong_hybrid
bool neg() const { return m_value < 0 && !m_unsigned; }
ulonglong abs() const
{
return neg() ? (ulonglong) -m_value : (ulonglong) m_value;
if (m_unsigned)
return (ulonglong) m_value;
if (m_value == LONGLONG_MIN) // avoid undefined behavior
return ((ulonglong) LONGLONG_MAX) + 1;
return m_value < 0 ? -m_value : m_value;
}
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment