summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormithun <mithun.c.y@oracle.com>2014-11-03 18:10:28 +0530
committermithun <mithun.c.y@oracle.com>2014-11-03 18:10:28 +0530
commitc5dfdec5682cd77896830cd225db68def54fc353 (patch)
treeb7a1f005db1edb9e24d60de582b9d02d7244106b
parentff906f032f9104222ee2bad19187238840a5af5d (diff)
downloadmariadb-git-c5dfdec5682cd77896830cd225db68def54fc353.tar.gz
Bug #19372926 : 5.5.38 FAILS FUNC_MATH MTR TEST.
Issue : ------- This seems for some platform -(LONGLONG_MIN) is not flagged as out of range. Fix: ---- Fix is backported from mysql-5.6 bug 14314156. Fixed by adding an explicit test for this value in Item_func_neg::int_op().
-rw-r--r--sql/item_func.cc8
-rw-r--r--sql/item_func.h5
2 files changed, 10 insertions, 3 deletions
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 96cf07550d8..bef48b1bfed 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -1760,7 +1760,13 @@ longlong Item_func_neg::int_op()
if ((null_value= args[0]->null_value))
return 0;
if (args[0]->unsigned_flag &&
- (ulonglong) value > (ulonglong) LONGLONG_MAX + 1)
+ (ulonglong) value > (ulonglong) LONGLONG_MAX + 1ULL)
+ return raise_integer_overflow();
+ // For some platforms we need special handling of LONGLONG_MIN to
+ // guarantee overflow.
+ if (value == LONGLONG_MIN &&
+ !args[0]->unsigned_flag &&
+ !unsigned_flag)
return raise_integer_overflow();
return check_integer_overflow(-value, !args[0]->unsigned_flag && value < 0);
}
diff --git a/sql/item_func.h b/sql/item_func.h
index 47a467f3580..fc9fa4a65fb 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -1,7 +1,7 @@
#ifndef ITEM_FUNC_INCLUDED
#define ITEM_FUNC_INCLUDED
-/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -251,7 +251,8 @@ public:
inline longlong check_integer_overflow(longlong value, bool val_unsigned)
{
if ((unsigned_flag && !val_unsigned && value < 0) ||
- (!unsigned_flag && val_unsigned && (ulonglong) value > LONGLONG_MAX))
+ (!unsigned_flag && val_unsigned &&
+ (ulonglong) value > (ulonglong) LONGLONG_MAX))
return raise_integer_overflow();
return value;
}