File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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.
You can’t perform that action at this time.
0 commit comments