summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <jimw@mysql.com>2005-09-22 11:40:22 -0700
committerunknown <jimw@mysql.com>2005-09-22 11:40:22 -0700
commit0f0f72c74f87c4cffca23704bd4a94b86b3945af (patch)
tree7a0080bcde54138749411a1c0af3a6cb0331d762
parentd2fc3bd4245f8c212046e88151da4a66d1b048b3 (diff)
downloadmariadb-git-0f0f72c74f87c4cffca23704bd4a94b86b3945af.tar.gz
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().
-rw-r--r--mysql-test/r/func_str.result6
-rw-r--r--mysql-test/t/func_str.test10
-rw-r--r--sql/item_strfunc.cc2
3 files changed, 18 insertions, 0 deletions
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(<decimal field with null>, 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();