Hi Martin,
On 7/2/09 9:28 AM, Martin Hansson wrote:
> #At file:///data0/martin/bzr/bug45261/5.1bt-gca-commit/ based on
> revid:davi.arnaut@stripped
>
> 2936 Martin Hansson 2009-07-02
> Bug#45261: Crash, stored procedure + decimal
>
[..]
>
> === modified file 'sql/sql_select.cc'
> --- a/sql/sql_select.cc 2009-06-07 20:40:53 +0000
> +++ b/sql/sql_select.cc 2009-07-02 12:27:56 +0000
> @@ -9389,14 +9389,16 @@ static Field *create_tmp_field_from_item
> bad and of course throws a truncation warning.
> +1: for decimal point
> */
> -
> - overflow= my_decimal_precision_to_length(intg + dec, dec,
> - item->unsigned_flag) - len;
> + const int required_length=
> + my_decimal_precision_to_length_no_truncation(intg + dec, dec,
> + item->unsigned_flag);
> + overflow= required_length - len;
>
> if (overflow> 0)
> dec= max(0, dec - overflow); // too long, discard fract
> else
> - len -= item->decimals - dec; // corrected value fits
> + /* Corrected value fits. */
> + len= required_length;
> }
>
> new_field= new Field_new_decimal(len, maybe_null, item->name,
>
I wonder whether we really need the overflow calculation since the
length is going to be truncated anyway. Perhaps we can replace it with
something like:
/* Maximum length. Automatically truncated to avoid overflow. */
len= my_decimal_precision_to_length(intg + dec, dec,
item->unsigned_flag);
/* Get the maximum number of decimal digits that can be stored. */
precision= my_decimal_length_to_precision(len, dec, item->unsigned_flag);
/* Throw out decimals if necessary. */
if (dec > precision)
dec= precision;
What do you think?