Hello Sergey,
You patch is ok to push. Please see a minor suggestion below.
On 03/22/2011 02:02 PM, Sergey Glukhov wrote:
> #At file:///home/gluh/MySQL/mysql-5.1/ based on
> revid:luis.soares@stripped
>
> 3618 Sergey Glukhov 2011-03-22
> 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
>
> modified:
> mysql-test/r/func_time.result
> mysql-test/t/func_time.test
> sql/item_timefunc.cc
> === modified file 'mysql-test/r/func_time.result'
> --- a/mysql-test/r/func_time.result 2011-02-02 18:13:11 +0000
> +++ b/mysql-test/r/func_time.result 2011-03-22 11:02:27 +0000
> @@ -1375,4 +1375,10 @@ Warning 1292 Truncated incorrect time va
> Warning 1292 Truncated incorrect time value: ''
> Warning 1292 Truncated incorrect time value: ''
> DROP TABLE t1;
> +#
> +# 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
>
> === modified file 'mysql-test/t/func_time.test'
> --- a/mysql-test/t/func_time.test 2011-02-02 18:13:11 +0000
> +++ b/mysql-test/t/func_time.test 2011-03-22 11:02:27 +0000
> @@ -881,4 +881,12 @@ INSERT INTO t1 VALUES (''),('');
> SELECT COUNT(*) FROM t1 GROUP BY TIME_TO_SEC(a);
> DROP TABLE t1;
>
> +--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
>
> === modified file 'sql/item_timefunc.cc'
> --- a/sql/item_timefunc.cc 2010-11-12 10:12:15 +0000
> +++ b/sql/item_timefunc.cc 2011-03-22 11:02:27 +0000
> @@ -3293,6 +3293,7 @@ void Item_func_str_to_date::fix_length_a
> {
> 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;
>
We use cached_format_type with const_item only, so we can move this initialization into
the inner "if":
--- old/sql/item_timefunc.cc 2010-11-12 10:12:15 +0000
+++ new/sql/item_timefunc.cc 2011-03-25 05:58:29 +0000
@@ -3298,6 +3298,7 @@ void Item_func_str_to_date::fix_length_a
cached_timestamp_type= MYSQL_TIMESTAMP_NONE;
if ((const_item= args[1]->const_item()))
{
+ cached_format_type= DATE_TIME;
char format_buff[64];
String format_str(format_buff, sizeof(format_buff), &my_charset_bin);
String *format= args[1]->val_str(&format_str);
or so.
Thank you,
Gleb