Skip to content

Commit 6a44f53

Browse files
author
Tor Didriksen
committed
Bug#14314156 MAIN.FUNC_MATH TEST FAILS ON MYSQL-TRUNK ON PB2
This seems to be a bug in gcc/clang/osx10.7-x86 -(LONGLONG_MIN) is not flagged as out of range. Fixed by adding an explicit test for this value in Item_func_neg::int_op()
1 parent cff1a10 commit 6a44f53

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

sql/item_func.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1936,7 +1936,13 @@ longlong Item_func_neg::int_op()
19361936
if ((null_value= args[0]->null_value))
19371937
return 0;
19381938
if (args[0]->unsigned_flag &&
1939-
(ulonglong) value > (ulonglong) LONGLONG_MAX + 1)
1939+
(ulonglong) value > (ulonglong) LONGLONG_MAX + 1ULL)
1940+
return raise_integer_overflow();
1941+
// For some platforms we need special handling of LONGLONG_MIN to
1942+
// guarantee overflow.
1943+
if (value == LONGLONG_MIN &&
1944+
!args[0]->unsigned_flag &&
1945+
!unsigned_flag)
19401946
return raise_integer_overflow();
19411947
return check_integer_overflow(-value, !args[0]->unsigned_flag && value < 0);
19421948
}

sql/item_func.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ class Item_func :public Item_result_field
272272
inline longlong check_integer_overflow(longlong value, bool val_unsigned)
273273
{
274274
if ((unsigned_flag && !val_unsigned && value < 0) ||
275-
(!unsigned_flag && val_unsigned && (ulonglong) value > LONGLONG_MAX))
275+
(!unsigned_flag && val_unsigned &&
276+
(ulonglong) value > (ulonglong) LONGLONG_MAX))
276277
return raise_integer_overflow();
277278
return value;
278279
}

unittest/gunit/item-t.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,18 @@ TEST_F(ItemTest, ItemFuncIntDivUnderflow)
293293
}
294294

295295

296+
TEST_F(ItemTest, ItemFuncNegLongLongMin)
297+
{
298+
// Bug#14314156 MAIN.FUNC_MATH TEST FAILS ON MYSQL-TRUNK ON PB2
299+
const longlong longlong_min= LONGLONG_MIN;
300+
Item_func_neg *item_neg= new Item_func_neg(new Item_int(longlong_min));
301+
302+
EXPECT_FALSE(item_neg->fix_fields(thd(), NULL));
303+
initializer.set_expected_error(ER_DATA_OUT_OF_RANGE);
304+
EXPECT_EQ(0, item_neg->int_op());
305+
}
306+
307+
296308
/*
297309
This is not an exhaustive test. It simply demonstrates that more of the
298310
initializations in mysqld.cc are needed for testing Item_xxx classes.

0 commit comments

Comments
 (0)