Browse Source

Backport into build-201102032246-5.1.52sp1

> ------------------------------------------------------------
> revno: 3507.1.7
> revision-id: guilhem@mysql.com-20101122085759-53uuoyqyjkh4em2m
> parent: davi.arnaut@oracle.com-20101120142951-l0f3bxmcwibcplxq
> committer: Guilhem Bichot <guilhem@mysql.com>
> branch nick: mysql-5.1-bugteam
> timestamp: Mon 2010-11-22 09:57:59 +0100
> message:
>   Fix for Bug#56138 "valgrind errors about overlapping memory when double-assigning same variable",
>   and related small fixes.
pull/73/head
MySQL Build Team 15 years ago
parent
commit
e92dff848f
  1. 3
      mysql-test/r/user_var.result
  2. 7
      mysql-test/t/user_var.test
  3. 7
      sql/field_conv.cc
  4. 2
      sql/item_func.cc
  5. 8
      sql/sql_select.cc

3
mysql-test/r/user_var.result

@ -447,4 +447,7 @@ IF(
count(*), 1)
1
DROP TABLE t1;
select @v:=@v:=sum(1) from dual;
@v:=@v:=sum(1)
1
End of 5.1 tests

7
mysql-test/t/user_var.test

@ -346,4 +346,11 @@ FROM t1 GROUP BY a LIMIT 1;
DROP TABLE t1;
#
# BUG#56138 "valgrind errors about overlapping memory when
# double-assigning same variable"
#
select @v:=@v:=sum(1) from dual;
--echo End of 5.1 tests

7
sql/field_conv.cc

@ -786,11 +786,8 @@ int field_conv(Field *to,Field *from)
((Field_varstring*)from)->length_bytes ==
((Field_varstring*)to)->length_bytes))
{ // Identical fields
#ifdef HAVE_purify
/* This may happen if one does 'UPDATE ... SET x=x' */
if (to->ptr != from->ptr)
#endif
memcpy(to->ptr,from->ptr,to->pack_length());
// to->ptr==from->ptr may happen if one does 'UPDATE ... SET x=x'
memmove(to->ptr, from->ptr, to->pack_length());
return 0;
}
}

2
sql/item_func.cc

@ -3913,7 +3913,7 @@ update_hash(user_var_entry *entry, bool set_null, void *ptr, uint length,
length--; // Fix length change above
entry->value[length]= 0; // Store end \0
}
memcpy(entry->value,ptr,length);
memmove(entry->value, ptr, length);
if (type == DECIMAL_RESULT)
((my_decimal*)entry->value)->fix_buffer_pointer();
entry->length= length;

8
sql/sql_select.cc

@ -4034,8 +4034,12 @@ update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,JOIN_TAB *join_tab,
continue;
}
#ifdef HAVE_purify
/* Valgrind complains about overlapped memcpy when save_pos==use. */
#if defined(__GNUC__) && !MY_GNUC_PREREQ(4,4)
/*
Old gcc used a memcpy(), which is undefined if save_pos==use:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19410
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39480
*/
if (save_pos != use)
#endif
*save_pos= *use;

Loading…
Cancel
Save