Properly handle the case where src==dst in upcall_vec_append.

This commit is contained in:
Michael Sullivan 2011-06-24 16:22:39 -07:00 committed by Brian Anderson
parent 36fb754476
commit 8ad7f3b56b

View File

@ -478,6 +478,12 @@ upcall_vec_append(rust_task *task, type_desc *t, type_desc *elem_t,
size_t n_dst_bytes = skip_null ? dst->fill - 1 : dst->fill;
rust_vec *new_vec = vec_grow(task, dst, n_src_bytes, &need_copy, t);
// If src and dst are the same (due to "v += v"), then dst getting
// resized causes src to move as well.
if (dst == src) {
src = new_vec;
}
if (need_copy) {
// Copy any dst elements in, omitting null if doing str.
copy_elements(task, elem_t, &new_vec->data, &dst->data, n_dst_bytes);