From 8ad7f3b56b79b13029384e51a201f495e0eb2a15 Mon Sep 17 00:00:00 2001 From: Michael Sullivan Date: Fri, 24 Jun 2011 16:22:39 -0700 Subject: [PATCH] Properly handle the case where src==dst in upcall_vec_append. --- src/rt/rust_upcall.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/rt/rust_upcall.cpp b/src/rt/rust_upcall.cpp index 022735f05dc..4681cbb8785 100644 --- a/src/rt/rust_upcall.cpp +++ b/src/rt/rust_upcall.cpp @@ -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);