From e0691da0c199ab2c65f4c9fb9681e4292c224a14 Mon Sep 17 00:00:00 2001 From: "kaa@polly.(none)" <> Date: Mon, 15 Oct 2007 10:34:34 +0400 Subject: [PATCH] Fix for bug #30453: String not cast to int correctly. Problem: my_strntoull10rnd_8bit() handled incorrectly cases when the input string contains a decimal point and is long enough to overrun the 'unsigned long long' type. The position of the decimal point was not taken into account which resulted in miscalculated numbers and truncation to appropriate SQL data type limits. Solution: Fix my_strntoull10rnd_8bit() to take the position of a decimal point into account in such cases. --- mysql-test/r/insert.result | 14 ++++++++++++++ mysql-test/t/insert.test | 15 +++++++++++++++ strings/ctype-simple.c | 14 +++++++++----- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/mysql-test/r/insert.result b/mysql-test/r/insert.result index 8a0a3ba848c..e1cad814226 100644 --- a/mysql-test/r/insert.result +++ b/mysql-test/r/insert.result @@ -461,4 +461,18 @@ i 2 2 DROP TABLE t1, t2; +CREATE TABLE t1 (c1 INT NOT NULL); +INSERT INTO t1 VALUES(4188.32999999999992724042385816574096679687500), +('4188.32999999999992724042385816574096679687500'), (4188); +SELECT * FROM t1; +c1 +4188 +4188 +4188 +CREATE TABLE t2 (c1 BIGINT); +INSERT INTO t2 VALUES('15449237462.0000000000'); +SELECT * FROM t2; +c1 +15449237462 +DROP TABLE t1, t2; End of 5.0 tests. diff --git a/mysql-test/t/insert.test b/mysql-test/t/insert.test index 76177403bd0..c36408a52fe 100644 --- a/mysql-test/t/insert.test +++ b/mysql-test/t/insert.test @@ -353,5 +353,20 @@ SELECT * FROM t2; DROP TABLE t1, t2; +# +# Bug #30453: String not cast to int correctly +# + +CREATE TABLE t1 (c1 INT NOT NULL); +INSERT INTO t1 VALUES(4188.32999999999992724042385816574096679687500), +('4188.32999999999992724042385816574096679687500'), (4188); +SELECT * FROM t1; + +CREATE TABLE t2 (c1 BIGINT); +INSERT INTO t2 VALUES('15449237462.0000000000'); +SELECT * FROM t2; + +DROP TABLE t1, t2; + --echo End of 5.0 tests. diff --git a/strings/ctype-simple.c b/strings/ctype-simple.c index 8b1b0d6790d..e073262cd4c 100644 --- a/strings/ctype-simple.c +++ b/strings/ctype-simple.c @@ -1538,14 +1538,18 @@ my_strntoull10rnd_8bit(CHARSET_INFO *cs __attribute__((unused)), } else addon= (*str >= '5'); - for ( ; str < end && (ch= (unsigned char) (*str - '0')) < 10; str++) + if (!dot) { - if (!dot) - shift++; + for ( ; str < end && (ch= (unsigned char) (*str - '0')) < 10; shift++, str++); + if (str < end && *str == '.') + { + str++; + for ( ; str < end && (ch= (unsigned char) (*str - '0')) < 10; str++); + } } - if (str < end && *str == '.' && !dot) + else { - str++; + shift= dot - str; for ( ; str < end && (ch= (unsigned char) (*str - '0')) < 10; str++); } goto exp;