Commit 30e5b4d7 authored by Sergei Golubchik's avatar Sergei Golubchik

lp:730637 - Valgrind warnings in 5.1-micro

sql/field.cc:
  initialize ltime completely
sql/filesort.cc:
  don't pack MYSQL_TIME if it's not initialized
  (safe here, but valgrind complains)
sql/item_cmpfunc.cc:
  don't pack MYSQL_TIME if it's not initialized
  (safe here, but valgrind complains)
sql/item_timefunc.cc:
  don't check MYSQL_TIME members if it's uninitialized
  (safe here, but valgrind complains)
sql/time.cc:
  use c_ptr_safe() instead of c_ptr()
  (make valgrind happy)
parent 19a3c29d
...@@ -1427,6 +1427,22 @@ Warning 1292 Incorrect datetime value: '2010-40-50' ...@@ -1427,6 +1427,22 @@ Warning 1292 Incorrect datetime value: '2010-40-50'
select subtime('0000-00-10 10:10:10', '30 10:00:00'); select subtime('0000-00-10 10:10:10', '30 10:00:00');
subtime('0000-00-10 10:10:10', '30 10:00:00') subtime('0000-00-10 10:10:10', '30 10:00:00')
NULL NULL
select cast(str_to_date(NULL, '%H:%i:%s') as time);
cast(str_to_date(NULL, '%H:%i:%s') as time)
NULL
create table t1 (a timestamp,key(a));
insert t1 values ('2010-01-01 02:03:04');
insert t1 select a + interval 1 day from t1;
insert t1 select a + interval 2 day from t1;
insert t1 select a + interval 4 day from t1;
insert t1 select a + interval 8 day from t1;
insert t1 select a + interval 16 day from t1;
explain select * from t1 where a > cast('2010-10-00 01:02:03' as datetime);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index a a 4 NULL 32 Using where; Using index
Warnings:
Warning 1292 Incorrect datetime value: '2010-10-00 01:02:03' for column 'a' at row 1
drop table t1;
select maketime(20,61,10)+0; select maketime(20,61,10)+0;
maketime(20,61,10)+0 maketime(20,61,10)+0
NULL NULL
...@@ -886,6 +886,18 @@ select truncate(date('2010-40-10'), 6); ...@@ -886,6 +886,18 @@ select truncate(date('2010-40-10'), 6);
select extract(month from '2010-40-50'); select extract(month from '2010-40-50');
select subtime('0000-00-10 10:10:10', '30 10:00:00'); select subtime('0000-00-10 10:10:10', '30 10:00:00');
select cast(str_to_date(NULL, '%H:%i:%s') as time);
create table t1 (a timestamp,key(a));
insert t1 values ('2010-01-01 02:03:04');
insert t1 select a + interval 1 day from t1;
insert t1 select a + interval 2 day from t1;
insert t1 select a + interval 4 day from t1;
insert t1 select a + interval 8 day from t1;
insert t1 select a + interval 16 day from t1;
explain select * from t1 where a > cast('2010-10-00 01:02:03' as datetime);
drop table t1;
# #
# lp:730627 TIME_to_ulonglong: Assertion `0' failed in 5.1-micro on wrong argument to MAKETIME # lp:730627 TIME_to_ulonglong: Assertion `0' failed in 5.1-micro on wrong argument to MAKETIME
# #
......
...@@ -5410,6 +5410,7 @@ String *Field_time::val_str(String *val_buffer, ...@@ -5410,6 +5410,7 @@ String *Field_time::val_str(String *val_buffer,
tmp= -tmp; tmp= -tmp;
ltime.neg= 1; ltime.neg= 1;
} }
ltime.year= ltime.month= 0;
ltime.day= (uint) 0; ltime.day= (uint) 0;
ltime.hour= (uint) (tmp/10000); ltime.hour= (uint) (tmp/10000);
ltime.minute= (uint) (tmp/100 % 100); ltime.minute= (uint) (tmp/100 % 100);
......
...@@ -850,7 +850,9 @@ static void make_sortkey(register SORTPARAM *param, ...@@ -850,7 +850,9 @@ static void make_sortkey(register SORTPARAM *param,
else else
{ {
MYSQL_TIME buf; MYSQL_TIME buf;
item->get_date_result(&buf, TIME_FUZZY_DATE | TIME_INVALID_DATES); if (item->get_date_result(&buf, TIME_FUZZY_DATE | TIME_INVALID_DATES))
DBUG_ASSERT(maybe_null && item->null_value);
else
value= pack_time(&buf); value= pack_time(&buf);
} }
if (maybe_null) if (maybe_null)
......
...@@ -842,7 +842,9 @@ get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg, ...@@ -842,7 +842,9 @@ get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg,
else else
{ {
MYSQL_TIME buf; MYSQL_TIME buf;
item->get_date_result(&buf, TIME_FUZZY_DATE | TIME_INVALID_DATES); if (item->get_date_result(&buf, TIME_FUZZY_DATE | TIME_INVALID_DATES))
DBUG_ASSERT(item->null_value);
else
value= pack_time(&buf); value= pack_time(&buf);
f_type= item->field_type(); // for Item_cache_int below. f_type= item->field_type(); // for Item_cache_int below.
} }
......
...@@ -2293,7 +2293,8 @@ void Item_char_typecast::fix_length_and_dec() ...@@ -2293,7 +2293,8 @@ void Item_char_typecast::fix_length_and_dec()
bool Item_time_typecast::get_date(MYSQL_TIME *ltime, uint fuzzy_date) bool Item_time_typecast::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
{ {
bool res= get_arg0_time(ltime); if (get_arg0_time(ltime))
return 1;
/* /*
MYSQL_TIMESTAMP_TIME value can have non-zero day part, MYSQL_TIMESTAMP_TIME value can have non-zero day part,
which we should not lose. which we should not lose.
...@@ -2301,16 +2302,17 @@ bool Item_time_typecast::get_date(MYSQL_TIME *ltime, uint fuzzy_date) ...@@ -2301,16 +2302,17 @@ bool Item_time_typecast::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
if (ltime->time_type != MYSQL_TIMESTAMP_TIME) if (ltime->time_type != MYSQL_TIMESTAMP_TIME)
ltime->year= ltime->month= ltime->day= 0; ltime->year= ltime->month= ltime->day= 0;
ltime->time_type= MYSQL_TIMESTAMP_TIME; ltime->time_type= MYSQL_TIMESTAMP_TIME;
return res; return 0;
} }
bool Item_date_typecast::get_date(MYSQL_TIME *ltime, uint fuzzy_date) bool Item_date_typecast::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
{ {
bool res= get_arg0_date(ltime, TIME_FUZZY_DATE); if (get_arg0_date(ltime, TIME_FUZZY_DATE))
return 1;
ltime->hour= ltime->minute= ltime->second= ltime->second_part= 0; ltime->hour= ltime->minute= ltime->second= ltime->second_part= 0;
ltime->time_type= MYSQL_TIMESTAMP_DATE; ltime->time_type= MYSQL_TIMESTAMP_DATE;
return res; return 0;
} }
bool Item_datetime_typecast::get_date(MYSQL_TIME *ltime, uint fuzzy_date) bool Item_datetime_typecast::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
......
...@@ -726,17 +726,17 @@ void make_truncated_value_warning(THD *thd, MYSQL_ERROR::enum_warning_level leve ...@@ -726,17 +726,17 @@ void make_truncated_value_warning(THD *thd, MYSQL_ERROR::enum_warning_level leve
if (field_name) if (field_name)
cs->cset->snprintf(cs, warn_buff, sizeof(warn_buff), cs->cset->snprintf(cs, warn_buff, sizeof(warn_buff),
ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD), ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
type_str, str.c_ptr(), field_name, type_str, str.c_ptr_safe(), field_name,
(ulong) thd->row_count); (ulong) thd->row_count);
else else
{ {
if (time_type > MYSQL_TIMESTAMP_ERROR) if (time_type > MYSQL_TIMESTAMP_ERROR)
cs->cset->snprintf(cs, warn_buff, sizeof(warn_buff), cs->cset->snprintf(cs, warn_buff, sizeof(warn_buff),
ER(ER_TRUNCATED_WRONG_VALUE), ER(ER_TRUNCATED_WRONG_VALUE),
type_str, str.c_ptr()); type_str, str.c_ptr_safe());
else else
cs->cset->snprintf(cs, warn_buff, sizeof(warn_buff), cs->cset->snprintf(cs, warn_buff, sizeof(warn_buff),
ER(ER_WRONG_VALUE), type_str, str.c_ptr()); ER(ER_WRONG_VALUE), type_str, str.c_ptr_safe());
} }
push_warning(thd, level, push_warning(thd, level,
ER_TRUNCATED_WRONG_VALUE, warn_buff); ER_TRUNCATED_WRONG_VALUE, warn_buff);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment