diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result index 464178124ecb7..b1862d46613af 100644 --- a/mysql-test/r/func_str.result +++ b/mysql-test/r/func_str.result @@ -4887,5 +4887,19 @@ id select_type table type possible_keys key key_len ref rows filtered Extra Warnings: Note 1003 select octet_length('a') AS `LENGTH('a')`,octet_length('a') AS `LENGTHB('a')` # +# MDEV-13555 Assertion `!item->null_value' failed in Type_handler::Item_send_str +# +CREATE TABLE t1 (c VARCHAR(8)); +INSERT INTO t1 VALUES (NULL),('bar'); +SELECT LPAD( c, 0, '?' ) FROM t1; +LPAD( c, 0, '?' ) +NULL + +SELECT RPAD( c, 0, '?' ) FROM t1; +RPAD( c, 0, '?' ) +NULL + +DROP TABLE t1; +# # End of 10.3 tests # diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test index 2f7dd638445a3..a75330ab981e4 100644 --- a/mysql-test/t/func_str.test +++ b/mysql-test/t/func_str.test @@ -1889,6 +1889,18 @@ DROP TABLE t1; SELECT LENGTHB('a'), LENGTHB(_utf8 0xC39F), LENGTHB(123), LENGTH(null); EXPLAIN EXTENDED SELECT LENGTH('a'), LENGTHB('a'); + +--echo # +--echo # MDEV-13555 Assertion `!item->null_value' failed in Type_handler::Item_send_str +--echo # + +CREATE TABLE t1 (c VARCHAR(8)); +INSERT INTO t1 VALUES (NULL),('bar'); +SELECT LPAD( c, 0, '?' ) FROM t1; +SELECT RPAD( c, 0, '?' ) FROM t1; +DROP TABLE t1; + + --echo # --echo # End of 10.3 tests --echo # diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 3b1dbf57fc4db..6138b67c02e04 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -3267,10 +3267,11 @@ String *Item_func_rpad::val_str(String *str) ((count < 0) && !args[1]->unsigned_flag)) goto err; + null_value=0; + if (count == 0) return make_empty_result(); - null_value=0; /* Assumes that the maximum length of a String is < INT_MAX32. */ /* Set here so that rest of code sees out-of-bound value as such. */ if ((ulonglong) count > INT_MAX32) @@ -3358,10 +3359,11 @@ String *Item_func_lpad::val_str(String *str) ((count < 0) && !args[1]->unsigned_flag)) goto err; + null_value=0; + if (count == 0) return make_empty_result(); - null_value=0; /* Assumes that the maximum length of a String is < INT_MAX32. */ /* Set here so that rest of code sees out-of-bound value as such. */ if ((ulonglong) count > INT_MAX32)