Skip to content

Commit bb089ce

Browse files
author
holyfoot/hf@mysql.com/hfmain.(none)
committed
bug #8663 cant use bigint unsigned as input to cast
in the case of the overflow in the decimal->integer conversion we didn't return the proper boundary value, but just the result of the conversion we calculated on the moment of the error
1 parent 11d5f7e commit bb089ce

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

mysql-test/r/bigint.result

+10
Original file line numberDiff line numberDiff line change
@@ -352,3 +352,13 @@ select c1 mod 50 as result from t1;
352352
result
353353
6
354354
drop table t1;
355+
select cast(19999999999999999999 as signed);
356+
cast(19999999999999999999 as signed)
357+
9223372036854775807
358+
Warnings:
359+
Error 1292 Truncated incorrect DECIMAL value: ''
360+
select cast(-19999999999999999999 as signed);
361+
cast(-19999999999999999999 as signed)
362+
-9223372036854775808
363+
Warnings:
364+
Error 1292 Truncated incorrect DECIMAL value: ''

mysql-test/t/bigint.test

+6
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,9 @@ insert into t1 values (10000002383263201056);
288288
select c1 mod 50 as result from t1;
289289
drop table t1;
290290

291+
#
292+
# Bug #8663 cant use bgint unsigned as input to cast
293+
#
294+
295+
select cast(19999999999999999999 as signed);
296+
select cast(-19999999999999999999 as signed);

strings/decimal.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,11 @@ int decimal2longlong(decimal_t *from, longlong *to)
10831083
x=x*DIG_BASE - *buf++;
10841084
if (unlikely(y < (LONGLONG_MIN/DIG_BASE) || x > y))
10851085
{
1086-
*to= from->sign ? y : -y;
1086+
/*
1087+
the decimal is bigger than any possible integer
1088+
return border integer depending on the sign
1089+
*/
1090+
*to= from->sign ? LONGLONG_MIN : LONGLONG_MAX;
10871091
return E_DEC_OVERFLOW;
10881092
}
10891093
}

0 commit comments

Comments
 (0)