Skip to content

Commit b514a5f

Browse files
committed
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"
1 parent 948e888 commit b514a5f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

sql/sql_type_int.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ class Longlong_hybrid
3333
bool neg() const { return m_value < 0 && !m_unsigned; }
3434
ulonglong abs() const
3535
{
36-
return neg() ? (ulonglong) -m_value : (ulonglong) m_value;
36+
if (m_unsigned)
37+
return (ulonglong) m_value;
38+
if (m_value == LONGLONG_MIN) // avoid undefined behavior
39+
return ((ulonglong) LONGLONG_MAX) + 1;
40+
return m_value < 0 ? -m_value : m_value;
3741
}
3842
};
3943

0 commit comments

Comments
 (0)