diff --git a/mysql-test/r/ctype_utf8.result b/mysql-test/r/ctype_utf8.result index a98beb36ef1..748361d3178 100644 --- a/mysql-test/r/ctype_utf8.result +++ b/mysql-test/r/ctype_utf8.result @@ -1001,6 +1001,9 @@ set @a:='bar'; execute my_stmt using @a; a b bar kostja +set @a:=NULL; +execute my_stmt using @a; +a b drop table t1; CREATE TABLE t1 ( a varchar(255) NOT NULL default '', diff --git a/mysql-test/t/ctype_utf8.test b/mysql-test/t/ctype_utf8.test index ede9665941a..e6342777839 100644 --- a/mysql-test/t/ctype_utf8.test +++ b/mysql-test/t/ctype_utf8.test @@ -840,6 +840,8 @@ insert into t1 values ('bar','kostja'); prepare my_stmt from "select * from t1 where a=?"; set @a:='bar'; execute my_stmt using @a; +set @a:=NULL; +execute my_stmt using @a; drop table t1; diff --git a/sql/item.cc b/sql/item.cc index 53640c4e44a..2d4f9138a51 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -290,7 +290,13 @@ Item *Item_param::safe_charset_converter(CHARSET_INFO *tocs) { Item_string *conv; uint conv_errors; - String tmp, cstr, *ostr= val_str(&tmp); + char buf[MAX_FIELD_WIDTH]; + String tmp(buf, sizeof(buf), &my_charset_bin); + String cstr, *ostr= val_str(&tmp); + /* + As safe_charset_converter is not executed for + a parameter bound to NULL, ostr should never be 0. + */ cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &conv_errors); if (conv_errors || !(conv= new Item_string(cstr.ptr(), cstr.length(), cstr.charset(),