mirror of
https://github.com/MariaDB/server.git
synced 2025-01-17 12:32:27 +01:00
Bug#15098 CAST(column double TO signed int), wrong result
field.cc: Adding longlong range checking to return LONGLONG_MIN or LONGLONG_MAX when out of range. Using (longlong) cast only when range is ok. cast.test: Adding test case. cast.result: Fixing results accordingly. sql/field.cc: Bug#15098 CAST(column double TO signed int), wrong result Adding longlong range checking. mysql-test/t/cast.test: Bug#15098 CAST(column double TO signed int), wrong result Adding longlong range checking. mysql-test/r/cast.result: Fixing results accordingly.
This commit is contained in:
parent
966ab524a3
commit
4ccd376100
3 changed files with 22 additions and 0 deletions
|
@ -267,3 +267,11 @@ Warning 1105 Cast to signed converted positive out-of-range integer to it's nega
|
|||
select cast(1.0e+300 as signed int);
|
||||
cast(1.0e+300 as signed int)
|
||||
9223372036854775807
|
||||
CREATE TABLE t1 (f1 double);
|
||||
INSERT INTO t1 SET f1 = -1.0e+30 ;
|
||||
INSERT INTO t1 SET f1 = +1.0e+30 ;
|
||||
SELECT f1 AS double_val, CAST(f1 AS SIGNED INT) AS cast_val FROM t1;
|
||||
double_val cast_val
|
||||
-1e+30 -9223372036854775808
|
||||
1e+30 9223372036854775807
|
||||
DROP TABLE t1;
|
||||
|
|
|
@ -152,4 +152,13 @@ select cast(repeat('1',20) as signed);
|
|||
#
|
||||
select cast(1.0e+300 as signed int);
|
||||
|
||||
#
|
||||
# Bugs: #15098: CAST(column double TO signed int), wrong result
|
||||
#
|
||||
CREATE TABLE t1 (f1 double);
|
||||
INSERT INTO t1 SET f1 = -1.0e+30 ;
|
||||
INSERT INTO t1 SET f1 = +1.0e+30 ;
|
||||
SELECT f1 AS double_val, CAST(f1 AS SIGNED INT) AS cast_val FROM t1;
|
||||
DROP TABLE t1;
|
||||
|
||||
# End of 4.1 tests
|
||||
|
|
|
@ -3385,6 +3385,11 @@ longlong Field_double::val_int(void)
|
|||
else
|
||||
#endif
|
||||
doubleget(j,ptr);
|
||||
/* Check whether we fit into longlong range */
|
||||
if (j <= (double) LONGLONG_MIN)
|
||||
return (longlong) LONGLONG_MIN;
|
||||
if (j >= (double) (ulonglong) LONGLONG_MAX)
|
||||
return (longlong) LONGLONG_MAX;
|
||||
return ((longlong) j);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue