From 36ab257491c3021680c4d845c4690e3e294c2436 Mon Sep 17 00:00:00 2001 From: Tor Didriksen Date: Wed, 17 Nov 2010 16:39:35 +0100 Subject: [PATCH] Bug #58137 char(0) column cause: my_gcvt: Assertion `width > 0 && to != ((void *)0)' failed mysql-test/r/func_math.result: Add test for Bug #58137 mysql-test/t/func_math.test: Add test for Bug #58137 sql/field.cc: Skip calling my_gcvt() if we are trying to insert a double into a char(0) column. --- mysql-test/r/func_math.result | 9 +++++++++ mysql-test/t/func_math.test | 8 ++++++++ sql/field.cc | 9 ++++++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/func_math.result b/mysql-test/r/func_math.result index bfb3af0afff..835715ac51e 100644 --- a/mysql-test/r/func_math.result +++ b/mysql-test/r/func_math.result @@ -607,3 +607,12 @@ SELECT floor(log10(format(concat_ws(5445796E25, 5306463, 30837), -358821))) as foo; foo 2 +# +# Bug #58137 char(0) column cause: +# my_gcvt: Assertion `width > 0 && to != ((void *)0)' failed +# +CREATE TABLE t1(a char(0)); +INSERT INTO t1 (SELECT -pi()); +Warnings: +Warning 1265 Data truncated for column 'a' at row 1 +DROP TABLE t1; diff --git a/mysql-test/t/func_math.test b/mysql-test/t/func_math.test index efdf7201a40..5d5dea74e28 100644 --- a/mysql-test/t/func_math.test +++ b/mysql-test/t/func_math.test @@ -464,3 +464,11 @@ SELECT -9223372036854775808 MOD -1; --echo # SELECT floor(log10(format(concat_ws(5445796E25, 5306463, 30837), -358821))) as foo; + +--echo # +--echo # Bug #58137 char(0) column cause: +--echo # my_gcvt: Assertion `width > 0 && to != ((void *)0)' failed +--echo # +CREATE TABLE t1(a char(0)); +INSERT INTO t1 (SELECT -pi()); +DROP TABLE t1; diff --git a/sql/field.cc b/sql/field.cc index a9b5fedda2d..e5cae9ea8e3 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -6327,10 +6327,13 @@ int Field_str::store(double nr) ASSERT_COLUMN_MARKED_FOR_WRITE; char buff[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE]; uint local_char_length= field_length / charset()->mbmaxlen; - size_t length; - my_bool error; + size_t length= 0; + my_bool error= (local_char_length == 0); + + // my_gcvt() requires width > 0, and we may have a CHAR(0) column. + if (!error) + length= my_gcvt(nr, MY_GCVT_ARG_DOUBLE, local_char_length, buff, &error); - length= my_gcvt(nr, MY_GCVT_ARG_DOUBLE, local_char_length, buff, &error); if (error) { if (table->in_use->abort_on_warning)