From 73b99f055ea6604f6a58580e8831b70a542a0443 Mon Sep 17 00:00:00 2001 From: mithun Date: Mon, 3 Nov 2014 18:10:28 +0530 Subject: [PATCH] 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(). sql/item_func.cc: For some platforms we need special handling of LONGLONG_MIN to guarantee overflow. --- sql/item_func.cc | 8 +++++++- sql/item_func.h | 5 +++-- 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; }