diff options
-rw-r--r-- | mysql-test/r/user_var.result | 3 | ||||
-rw-r--r-- | mysql-test/t/user_var.test | 7 | ||||
-rw-r--r-- | sql/field_conv.cc | 7 | ||||
-rw-r--r-- | sql/item_func.cc | 2 | ||||
-rw-r--r-- | sql/sql_select.cc | 8 |
5 files changed, 19 insertions, 8 deletions
diff --git a/mysql-test/r/user_var.result b/mysql-test/r/user_var.result index a680e837cae..e41a9bc7637 100644 --- a/mysql-test/r/user_var.result +++ b/mysql-test/r/user_var.result @@ -445,6 +445,9 @@ IF( count(*), 1) 1 DROP TABLE t1; +select @v:=@v:=sum(1) from dual; +@v:=@v:=sum(1) +1 End of 5.1 tests DROP TABLE IF EXISTS t1; CREATE TABLE t1(f1 INT AUTO_INCREMENT, PRIMARY KEY(f1)); diff --git a/mysql-test/t/user_var.test b/mysql-test/t/user_var.test index 06508c43766..b1a54495330 100644 --- a/mysql-test/t/user_var.test +++ b/mysql-test/t/user_var.test @@ -344,6 +344,13 @@ 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 # diff --git a/sql/field_conv.cc b/sql/field_conv.cc index ea6ff82e0aa..20c647ccc00 100644 --- a/sql/field_conv.cc +++ b/sql/field_conv.cc @@ -787,11 +787,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; } } diff --git a/sql/item_func.cc b/sql/item_func.cc index bef0e461a1f..4551962a2c1 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -4331,7 +4331,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; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index e9373bc455f..066b279cba0 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -4050,8 +4050,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; |