From d6125b27b38432d1a465397c0c5a9e62bb1c65d3 Mon Sep 17 00:00:00 2001 From: Sergey Glukhov <sergey.glukhov@oracle.com> Date: Mon, 28 Mar 2011 17:24:25 +0400 Subject: [PATCH] Bug#11765216 58154: UNINITIALIZED VARIABLE FORMAT IN STR_TO_DATE FUNCTION Valgrind warning happens due to uninitialized cached_format_type field which is used later in Item_func_str_to_date::val_str method. The fix is to init cached_format_type field. mysql-test/r/func_time.result: test case mysql-test/t/func_time.test: test case sql/item_timefunc.cc: init cached_format_type field --- mysql-test/r/func_time.result | 6 ++++++ mysql-test/t/func_time.test | 8 ++++++++ sql/item_timefunc.cc | 1 + 3 files changed, 15 insertions(+) diff --git a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result index f63860039d..01743e4a1d 100644 --- a/mysql-test/r/func_time.result +++ b/mysql-test/r/func_time.result @@ -1381,4 +1381,10 @@ DROP TABLE t1; SELECT STR_TO_DATE(SPACE(2),'1'); STR_TO_DATE(SPACE(2),'1') 0000-00-00 +# +# Bug#11765216 58154: UNINITIALIZED VARIABLE FORMAT IN STR_TO_DATE FUNCTION +# +SET GLOBAL SQL_MODE=''; +DO STR_TO_DATE((''), FROM_DAYS(@@GLOBAL.SQL_MODE)); +SET GLOBAL SQL_MODE=DEFAULT; End of 5.1 tests diff --git a/mysql-test/t/func_time.test b/mysql-test/t/func_time.test index c48351d33f..3f441c42d4 100644 --- a/mysql-test/t/func_time.test +++ b/mysql-test/t/func_time.test @@ -887,4 +887,12 @@ DROP TABLE t1; SELECT STR_TO_DATE(SPACE(2),'1'); +--echo # +--echo # Bug#11765216 58154: UNINITIALIZED VARIABLE FORMAT IN STR_TO_DATE FUNCTION +--echo # + +SET GLOBAL SQL_MODE=''; +DO STR_TO_DATE((''), FROM_DAYS(@@GLOBAL.SQL_MODE)); +SET GLOBAL SQL_MODE=DEFAULT; + --echo End of 5.1 tests diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 71b2baf4fe..ecf790cc06 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -3293,6 +3293,7 @@ void Item_func_str_to_date::fix_length_and_dec() { maybe_null= 1; decimals=0; + cached_format_type= DATE_TIME; cached_field_type= MYSQL_TYPE_DATETIME; max_length= MAX_DATETIME_FULL_WIDTH*MY_CHARSET_BIN_MB_MAXLEN; cached_timestamp_type= MYSQL_TIMESTAMP_NONE; -- 2.30.9