Skip to content
Permalink
Browse files
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"
  • Loading branch information
abarkov committed Sep 21, 2018
1 parent 948e888 commit b514a5f
Showing 1 changed file with 5 additions and 1 deletion.
@@ -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;
}
};

0 comments on commit b514a5f

Please sign in to comment.