From 82b7c54338a3465790e4e64a647e82b9d7ea59b6 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 9 May 2007 17:27:14 +0500 Subject: Bug #27957 cast as decimal does not check overflow, also inconsistent with group, subselect Missing check for overflow added to the Item_decimal_typecast::val_decimal include/decimal.h: Bug #27957 cast as decimal does not check overflow, also inconsistent with group, subselect decimal_intg() declaration mysql-test/r/cast.result: Bug #27957 cast as decimal does not check overflow, also inconsistent with group, subselect result fixed mysql-test/r/type_newdecimal.result: Bug #27957 cast as decimal does not check overflow, also inconsistent with group, subselect test result mysql-test/t/type_newdecimal.test: Bug #27957 cast as decimal does not check overflow, also inconsistent with group, subselect test case added sql/item_func.cc: Bug #27957 cast as decimal does not check overflow, also inconsistent with group, subselect now we check for possible ovreflow in Item_decimal_typecast::val_decimal sql/my_decimal.h: Bug #27957 cast as decimal does not check overflow, also inconsistent with group, subselect my_decimal_intg() implemented strings/decimal.c: Bug #27957 cast as decimal does not check overflow, also inconsistent with group, subselect decimal_intg() implemented --- sql/item_func.cc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'sql/item_func.cc') diff --git a/sql/item_func.cc b/sql/item_func.cc index e761cf7fb43..382e197acfe 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -1050,9 +1050,32 @@ longlong Item_decimal_typecast::val_int() my_decimal *Item_decimal_typecast::val_decimal(my_decimal *dec) { my_decimal tmp_buf, *tmp= args[0]->val_decimal(&tmp_buf); + bool sign; if ((null_value= args[0]->null_value)) return NULL; my_decimal_round(E_DEC_FATAL_ERROR, tmp, decimals, FALSE, dec); + sign= dec->sign(); + if (unsigned_flag) + { + if (sign) + { + my_decimal_set_zero(dec); + goto err; + } + } + if (max_length - 2 - decimals < (uint) my_decimal_intg(dec)) + { + max_my_decimal(dec, max_length - 2, decimals); + dec->sign(sign); + goto err; + } + return dec; + +err: + push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR, + ER_WARN_DATA_OUT_OF_RANGE, + ER(ER_WARN_DATA_OUT_OF_RANGE), + name, 1); return dec; } -- cgit v1.2.1