Skip to content

Commit aa508d4

Browse files
author
Sergey Glukhov
committed
Bug#11766126 59166: ANOTHER DATETIME VALGRIND UNINITIALIZED WARNING
Valgrind warning happens because null values check happens too late in Item_func_month::val_str(after result string calculation).The fix is to check null value before result string calculation. --BZR-- revision-id: [email protected] property-branch-nick: mysql-5.1 property-file-info: ld7:file_id69:sp1f-func_time.result-20001228015633-voo54ouzgwctcbmk22zwazoev5os5o4x7:message10:test case property-file-info: 4:path29:mysql-test/r/func_time.resulted7:file_id67:sp1f-func_time.test-20001228015636-a35kjdfabkx5uhymtqrz4c366obz4i7h7:message10:test case property-file-info: 4:path27:mysql-test/t/func_time.tested7:file_id68:sp1f-item_timefunc.h-19700101030959-o34ypz6ggolzqmhgsjnqh6inkvgugi467:message50:check null value before result string calculation.4:path19:sql/item_timefunc.hee testament3-sha1: afaa9ad345fdd56c5ecbcea857bde790dcacad5d
1 parent 17e7472 commit aa508d4

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

mysql-test/r/func_time.result

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,4 +1393,10 @@ SET GLOBAL SQL_MODE=DEFAULT;
13931393
SELECT FORMAT(YEAR(STR_TO_DATE('',GET_FORMAT(TIME,''))),1);
13941394
FORMAT(YEAR(STR_TO_DATE('',GET_FORMAT(TIME,''))),1)
13951395
NULL
1396+
#
1397+
# Bug#11766126 59166: ANOTHER DATETIME VALGRIND UNINITIALIZED WARNING
1398+
#
1399+
SELECT CAST((MONTH(FROM_UNIXTIME(@@GLOBAL.SQL_MODE))) AS BINARY(1025));
1400+
CAST((MONTH(FROM_UNIXTIME(@@GLOBAL.SQL_MODE))) AS BINARY(1025))
1401+
NULL
13961402
End of 5.1 tests

mysql-test/t/func_time.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,4 +901,10 @@ SET GLOBAL SQL_MODE=DEFAULT;
901901

902902
SELECT FORMAT(YEAR(STR_TO_DATE('',GET_FORMAT(TIME,''))),1);
903903

904+
--echo #
905+
--echo # Bug#11766126 59166: ANOTHER DATETIME VALGRIND UNINITIALIZED WARNING
906+
--echo #
907+
908+
SELECT CAST((MONTH(FROM_UNIXTIME(@@GLOBAL.SQL_MODE))) AS BINARY(1025));
909+
904910
--echo End of 5.1 tests

sql/item_timefunc.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,11 @@ class Item_func_month :public Item_func
106106
{ DBUG_ASSERT(fixed == 1); return (double) Item_func_month::val_int(); }
107107
String *val_str(String *str)
108108
{
109-
str->set(val_int(), &my_charset_bin);
110-
return null_value ? 0 : str;
109+
longlong nr= val_int();
110+
if (null_value)
111+
return 0;
112+
str->set(nr, &my_charset_bin);
113+
return str;
111114
}
112115
const char *func_name() const { return "month"; }
113116
enum Item_result result_type () const { return INT_RESULT; }

0 commit comments

Comments
 (0)