Browse Source

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)
pull/374/head
Sergei Golubchik 15 years ago
parent
commit
30e5b4d719
  1. 16
      mysql-test/r/func_time.result
  2. 12
      mysql-test/t/func_time.test
  3. 1
      sql/field.cc
  4. 6
      sql/filesort.cc
  5. 6
      sql/item_cmpfunc.cc
  6. 10
      sql/item_timefunc.cc
  7. 6
      sql/time.cc

16
mysql-test/r/func_time.result

@ -1427,6 +1427,22 @@ Warning 1292 Incorrect datetime value: '2010-40-50'
select subtime('0000-00-10 10:10:10', '30 10:00:00');
subtime('0000-00-10 10:10:10', '30 10:00:00')
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;
maketime(20,61,10)+0
NULL

12
mysql-test/t/func_time.test

@ -886,6 +886,18 @@ select truncate(date('2010-40-10'), 6);
select extract(month from '2010-40-50');
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
#

1
sql/field.cc

@ -5410,6 +5410,7 @@ String *Field_time::val_str(String *val_buffer,
tmp= -tmp;
ltime.neg= 1;
}
ltime.year= ltime.month= 0;
ltime.day= (uint) 0;
ltime.hour= (uint) (tmp/10000);
ltime.minute= (uint) (tmp/100 % 100);

6
sql/filesort.cc

@ -850,8 +850,10 @@ static void make_sortkey(register SORTPARAM *param,
else
{
MYSQL_TIME buf;
item->get_date_result(&buf, TIME_FUZZY_DATE | TIME_INVALID_DATES);
value= pack_time(&buf);
if (item->get_date_result(&buf, TIME_FUZZY_DATE | TIME_INVALID_DATES))
DBUG_ASSERT(maybe_null && item->null_value);
else
value= pack_time(&buf);
}
if (maybe_null)
{

6
sql/item_cmpfunc.cc

@ -842,8 +842,10 @@ get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg,
else
{
MYSQL_TIME buf;
item->get_date_result(&buf, TIME_FUZZY_DATE | TIME_INVALID_DATES);
value= pack_time(&buf);
if (item->get_date_result(&buf, TIME_FUZZY_DATE | TIME_INVALID_DATES))
DBUG_ASSERT(item->null_value);
else
value= pack_time(&buf);
f_type= item->field_type(); // for Item_cache_int below.
}
break;

10
sql/item_timefunc.cc

@ -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 res= get_arg0_time(ltime);
if (get_arg0_time(ltime))
return 1;
/*
MYSQL_TIMESTAMP_TIME value can have non-zero day part,
which we should not lose.
@ -2301,16 +2302,17 @@ bool Item_time_typecast::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
if (ltime->time_type != MYSQL_TIMESTAMP_TIME)
ltime->year= ltime->month= ltime->day= 0;
ltime->time_type= MYSQL_TIMESTAMP_TIME;
return res;
return 0;
}
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->time_type= MYSQL_TIMESTAMP_DATE;
return res;
return 0;
}
bool Item_datetime_typecast::get_date(MYSQL_TIME *ltime, uint fuzzy_date)

6
sql/time.cc

@ -726,17 +726,17 @@ void make_truncated_value_warning(THD *thd, MYSQL_ERROR::enum_warning_level leve
if (field_name)
cs->cset->snprintf(cs, warn_buff, sizeof(warn_buff),
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);
else
{
if (time_type > MYSQL_TIMESTAMP_ERROR)
cs->cset->snprintf(cs, warn_buff, sizeof(warn_buff),
ER(ER_TRUNCATED_WRONG_VALUE),
type_str, str.c_ptr());
type_str, str.c_ptr_safe());
else
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,
ER_TRUNCATED_WRONG_VALUE, warn_buff);

Loading…
Cancel
Save