Commit 768c56e4 authored by Tor Didriksen's avatar Tor Didriksen

Bug #59686 crash in String::copy() with time data type

The problem was that Item_sum_hybrid::val_xxx() did not propagate null values
up the expression tree.


mysql-test/r/func_time.result:
  New test case.
mysql-test/t/func_time.test:
  New test case.
sql/item_sum.cc:
  Check for null_value when evaluating sub-items in sub-trees in Item_sum_hybrid::val_xxx()
parent 1756d087
...@@ -1368,3 +1368,15 @@ SELECT SUBDATE(STR_TO_DATE(NULL,0), INTERVAL 1 HOUR); ...@@ -1368,3 +1368,15 @@ SELECT SUBDATE(STR_TO_DATE(NULL,0), INTERVAL 1 HOUR);
SUBDATE(STR_TO_DATE(NULL,0), INTERVAL 1 HOUR) SUBDATE(STR_TO_DATE(NULL,0), INTERVAL 1 HOUR)
NULL NULL
# #
# Bug #59686 crash in String::copy() with time data type
#
SELECT min(timestampadd(month, 1>'', from_days('%Z')));
min(timestampadd(month, 1>'', from_days('%Z')))
NULL
Warnings:
Warning 1292 Truncated incorrect INTEGER value: '%Z'
create table t1(a time);
insert into t1 values ('00:00:00'),('00:01:00');
select 1 from t1 where 1 < some (select cast(a as datetime) from t1);
1
drop table t1;
...@@ -881,4 +881,12 @@ SELECT WEEK(STR_TO_DATE(NULL,0)); ...@@ -881,4 +881,12 @@ SELECT WEEK(STR_TO_DATE(NULL,0));
SELECT SUBDATE(STR_TO_DATE(NULL,0), INTERVAL 1 HOUR); SELECT SUBDATE(STR_TO_DATE(NULL,0), INTERVAL 1 HOUR);
--echo # --echo #
--echo # Bug #59686 crash in String::copy() with time data type
--echo #
SELECT min(timestampadd(month, 1>'', from_days('%Z')));
create table t1(a time);
insert into t1 values ('00:00:00'),('00:01:00');
select 1 from t1 where 1 < some (select cast(a as datetime) from t1);
drop table t1;
...@@ -1903,7 +1903,10 @@ double Item_sum_hybrid::val_real() ...@@ -1903,7 +1903,10 @@ double Item_sum_hybrid::val_real()
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
if (null_value) if (null_value)
return 0.0; return 0.0;
return value->val_real(); double retval= value->val_real();
if ((null_value= value->null_value))
DBUG_ASSERT(retval == 0.0);
return retval;
} }
longlong Item_sum_hybrid::val_int() longlong Item_sum_hybrid::val_int()
...@@ -1911,7 +1914,10 @@ longlong Item_sum_hybrid::val_int() ...@@ -1911,7 +1914,10 @@ longlong Item_sum_hybrid::val_int()
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
if (null_value) if (null_value)
return 0; return 0;
return value->val_int(); longlong retval= value->val_int();
if ((null_value= value->null_value))
DBUG_ASSERT(retval == 0);
return retval;
} }
...@@ -1920,7 +1926,10 @@ my_decimal *Item_sum_hybrid::val_decimal(my_decimal *val) ...@@ -1920,7 +1926,10 @@ my_decimal *Item_sum_hybrid::val_decimal(my_decimal *val)
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
if (null_value) if (null_value)
return 0; return 0;
return value->val_decimal(val); my_decimal *retval= value->val_decimal(val);
if ((null_value= value->null_value))
DBUG_ASSERT(retval == NULL);
return retval;
} }
...@@ -1930,7 +1939,10 @@ Item_sum_hybrid::val_str(String *str) ...@@ -1930,7 +1939,10 @@ Item_sum_hybrid::val_str(String *str)
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
if (null_value) if (null_value)
return 0; return 0;
return value->val_str(str); String *retval= value->val_str(str);
if ((null_value= value->null_value))
DBUG_ASSERT(retval == NULL);
return retval;
} }
......
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