summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.com>2018-09-21 18:03:23 +0400
committerAlexander Barkov <bar@mariadb.com>2018-09-21 18:03:23 +0400
commitb514a5f9e887911d5d5b46c91f4cfbe87c346289 (patch)
tree6ac3804eb5912f4ce00921f1976daf91d6b05b76
parent948e888097b8ddc22167f2d61726adb0cdd88215 (diff)
downloadmariadb-git-b514a5f9e887911d5d5b46c91f4cfbe87c346289.tar.gz
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"
-rw-r--r--sql/sql_type_int.h6
1 files changed, 5 insertions, 1 deletions
diff --git a/sql/sql_type_int.h b/sql/sql_type_int.h
index 055790ba431..1eda5651df5 100644
--- a/sql/sql_type_int.h
+++ b/sql/sql_type_int.h
@@ -33,7 +33,11 @@ public:
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;
}
};