summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <jimw@mysql.com>2005-09-22 15:59:13 -0700
committerunknown <jimw@mysql.com>2005-09-22 15:59:13 -0700
commit13fa84a7e2f25f69fcaf8ad5893ac6fe152d6ff8 (patch)
treed7153c4337a3eb84f2a213da38023db6748d08ec
parent443b394fc31898b2903ab48b43dd20dc7826733e (diff)
downloadmariadb-git-13fa84a7e2f25f69fcaf8ad5893ac6fe152d6ff8.tar.gz
Fix CAST(1.0e+300 TO SIGNED). (Bug #13344)
mysql-test/r/cast.result: Update results mysql-test/t/cast.test: Add regression test sql/item.h: Cap Item_real::val_int() to LONGLONG_MIN and LONGLONG_MAX.
-rw-r--r--mysql-test/r/cast.result3
-rw-r--r--mysql-test/t/cast.test5
-rw-r--r--sql/item.h8
3 files changed, 16 insertions, 0 deletions
diff --git a/mysql-test/r/cast.result b/mysql-test/r/cast.result
index 7cd0934f7a3..d5d679a0ae8 100644
--- a/mysql-test/r/cast.result
+++ b/mysql-test/r/cast.result
@@ -252,3 +252,6 @@ cast(repeat('1',20) as signed)
-7335632962598440505
Warnings:
Warning 1105 Cast to signed converted positive out-of-range integer to it's negative complement
+select cast(1.0e+300 as signed int);
+cast(1.0e+300 as signed int)
+9223372036854775807
diff --git a/mysql-test/t/cast.test b/mysql-test/t/cast.test
index 394971f9648..e883788be51 100644
--- a/mysql-test/t/cast.test
+++ b/mysql-test/t/cast.test
@@ -143,4 +143,9 @@ select cast(concat('184467440','73709551615') as signed);
select cast(repeat('1',20) as unsigned);
select cast(repeat('1',20) as signed);
+#
+# Bug #13344: cast of large decimal to signed int not handled correctly
+#
+select cast(1.0e+300 as signed int);
+
# End of 4.1 tests
diff --git a/sql/item.h b/sql/item.h
index e683cda5786..f55707cfc32 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -703,6 +703,14 @@ public:
longlong val_int()
{
DBUG_ASSERT(fixed == 1);
+ if (value <= (double) LONGLONG_MIN)
+ {
+ return LONGLONG_MIN;
+ }
+ else if (value >= (double) (ulonglong) LONGLONG_MAX)
+ {
+ return LONGLONG_MAX;
+ }
return (longlong) (value+(value > 0 ? 0.5 : -0.5));
}
String *val_str(String*);