Commit d214f3d6 authored by Evgeny Potemkin's avatar Evgeny Potemkin

Bug#56120: Failed assertion on MIX/MAX on negative time value

The Item_cache_datetime::val_str function wasn't taking into account that time
could be negative. This led to failed assertion.
Now Item_cache_datetime::val_str correctly converts negative time values
from integer to string representation.

mysql-test/r/func_group.result:
  Added a test case for the bug#56120.
mysql-test/t/func_group.test:
  Added a test case for the bug#56120.
sql/item.cc:
  Bug#56120: Failed assertion on MIX/MAX on negative time value
  Now Item_cache_datetime::val_str correctly converts negative time values
  from integer to string representation.
parent d8a9ed0e
......@@ -1715,7 +1715,7 @@ drop table t1;
#
End of 5.1 tests
#
# Bug#55648: Server crash on MIX/MAX on maximum time value
# Bug#55648: Server crash on MIN/MAX on maximum time value
#
CREATE TABLE t1(c1 TIME NOT NULL);
INSERT INTO t1 VALUES('837:59:59');
......@@ -1725,3 +1725,13 @@ MAX(c1)
838:59:59
DROP TABLE t1;
# End of the bug#55648
#
# Bug#56120: Failed assertion on MIN/MAX on negative time value
#
CREATE TABLE t1(c1 TIME NOT NULL);
INSERT INTO t1 VALUES('-00:00:01');
SELECT MAX(c1),MIN(c1) FROM t1;
MAX(c1) MIN(c1)
-00:00:01 -00:00:01
DROP TABLE t1;
# End of the bug#56120
......@@ -1086,7 +1086,7 @@ drop table t1;
--echo End of 5.1 tests
--echo #
--echo # Bug#55648: Server crash on MIX/MAX on maximum time value
--echo # Bug#55648: Server crash on MIN/MAX on maximum time value
--echo #
CREATE TABLE t1(c1 TIME NOT NULL);
INSERT INTO t1 VALUES('837:59:59');
......@@ -1095,3 +1095,12 @@ SELECT MAX(c1) FROM t1;
DROP TABLE t1;
--echo # End of the bug#55648
--echo #
--echo # Bug#56120: Failed assertion on MIN/MAX on negative time value
--echo #
CREATE TABLE t1(c1 TIME NOT NULL);
INSERT INTO t1 VALUES('-00:00:01');
SELECT MAX(c1),MIN(c1) FROM t1;
DROP TABLE t1;
--echo # End of the bug#56120
......@@ -7510,9 +7510,14 @@ String *Item_cache_datetime::val_str(String *str)
return NULL;
if (cached_field_type == MYSQL_TYPE_TIME)
{
ulonglong time= int_value;
DBUG_ASSERT(time <= TIME_MAX_VALUE);
longlong time= int_value;
set_zero_time(&ltime, MYSQL_TIMESTAMP_TIME);
if (time < 0)
{
time= -time;
ltime.neg= TRUE;
}
DBUG_ASSERT(time <= TIME_MAX_VALUE);
ltime.second= time % 100;
time/= 100;
ltime.minute= time % 100;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment