From b5af427b7c22798cd8888eeef714579409f7c7ce Mon Sep 17 00:00:00 2001 From: Alexander Peresypkin <7003484@gmail.com> Date: Mon, 5 Aug 2019 20:17:36 +0200 Subject: [PATCH] Fix bugs: https://bugs.mysql.com/bug.php?id=95964 https://bugs.mysql.com/bug.php?id=95983 --- mysql-test/r/bugs95964_95983.result | 18 ++++++++++++++++++ mysql-test/t/bugs95964_95983.test | 16 ++++++++++++++++ sql/item.cc | 5 ++++- 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 mysql-test/r/bugs95964_95983.result create mode 100644 mysql-test/t/bugs95964_95983.test diff --git a/mysql-test/r/bugs95964_95983.result b/mysql-test/r/bugs95964_95983.result new file mode 100644 index 00000000000..781c642fd3f --- /dev/null +++ b/mysql-test/r/bugs95964_95983.result @@ -0,0 +1,18 @@ +DROP TABLE IF EXISTS t0, t1; +CREATE TABLE t0(c0 INT); +CREATE TABLE t1(c0 INT) ENGINE = MEMORY; +INSERT INTO t0(c0) VALUES(0); +INSERT INTO t1(c0) VALUES(-1); +SELECT * FROM t0, t1 WHERE (CAST(t1.c0 AS UNSIGNED)) > (IFNULL("u", t0.c0)); +c0 c0 +0 -1 +SELECT (CAST(t1.c0 AS UNSIGNED)) > (IFNULL("u", t0.c0)) FROM t0, t1; +(CAST(t1.c0 AS UNSIGNED)) > (IFNULL("u", t0.c0)) +1 +DROP TABLE t0, t1; +CREATE TABLE t0(c0 INT, c1 TEXT); +INSERT INTO t0(c0, c1) VALUES(-1, "a"); +SELECT * FROM t0 WHERE t0.c1 < (t0.c0 & t0.c0) AND t0.c0 = -1; +c0 c1 +-1 a +DROP TABLE t0; diff --git a/mysql-test/t/bugs95964_95983.test b/mysql-test/t/bugs95964_95983.test new file mode 100644 index 00000000000..913bd426106 --- /dev/null +++ b/mysql-test/t/bugs95964_95983.test @@ -0,0 +1,16 @@ +--disable_warnings +DROP TABLE IF EXISTS t0, t1; +--enable_warnings + +CREATE TABLE t0(c0 INT); +CREATE TABLE t1(c0 INT) ENGINE = MEMORY; +INSERT INTO t0(c0) VALUES(0); +INSERT INTO t1(c0) VALUES(-1); +SELECT * FROM t0, t1 WHERE (CAST(t1.c0 AS UNSIGNED)) > (IFNULL("u", t0.c0)); +SELECT (CAST(t1.c0 AS UNSIGNED)) > (IFNULL("u", t0.c0)) FROM t0, t1; +DROP TABLE t0, t1; + +CREATE TABLE t0(c0 INT, c1 TEXT); +INSERT INTO t0(c0, c1) VALUES(-1, "a"); +SELECT * FROM t0 WHERE t0.c1 < (t0.c0 & t0.c0) AND t0.c0 = -1; +DROP TABLE t0; diff --git a/sql/item.cc b/sql/item.cc index 038212314f9..39ed6707f09 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -8715,7 +8715,10 @@ double Item_cache_int::val_real() DBUG_ASSERT(fixed == 1); if (!has_value()) return 0.0; - return (double) value; + if (unsigned_flag) { + return static_cast(static_cast(value)); + } + return static_cast(value); } longlong Item_cache_int::val_int()