From 0f0f72c74f87c4cffca23704bd4a94b86b3945af Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 22 Sep 2005 11:40:22 -0700 Subject: [PATCH] Fix handling of NULL values in decimal fields in FORMAT(). (Bug #13361) mysql-test/r/func_str.result: Add new results mysql-test/t/func_str.test: Add new regression test sql/item_strfunc.cc: Handle NULL decimal fields in FORMAT(). --- mysql-test/r/func_str.result | 6 ++++++ mysql-test/t/func_str.test | 10 ++++++++++ sql/item_strfunc.cc | 2 ++ 3 files changed, 18 insertions(+) diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result index 577f943ebde..3d7d693cdce 100644 --- a/mysql-test/r/func_str.result +++ b/mysql-test/r/func_str.result @@ -1011,3 +1011,9 @@ t 1000000 1 drop table t1; +create table t1 (d decimal default null); +insert into t1 values (null); +select format(d, 2) from t1; +format(d, 2) +NULL +drop table t1; diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test index 4a6c98c8d7f..5f32b7b2b49 100644 --- a/mysql-test/t/func_str.test +++ b/mysql-test/t/func_str.test @@ -665,3 +665,13 @@ select rpad(i, 7, ' ') as t from t1; drop table t1; # End of 4.1 tests + +# +# Bug #13361: SELECT FORMAT(, 2) crashes +# +create table t1 (d decimal default null); +insert into t1 values (null); +select format(d, 2) from t1; +drop table t1; + +# End of 5.0 tests diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 54c476ce176..b9ae3140393 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1733,6 +1733,8 @@ String *Item_func_format::val_str(String *str) { my_decimal dec_val, rnd_dec, *res; res= args[0]->val_decimal(&dec_val); + if ((null_value=args[0]->null_value)) + return 0; /* purecov: inspected */ my_decimal_round(E_DEC_FATAL_ERROR, res, decimals, false, &rnd_dec); my_decimal2string(E_DEC_FATAL_ERROR, &rnd_dec, 0, 0, 0, str); str_length= str->length();