Skip to content

Commit 8ad7f3b

Browse files
msullivanbrson
authored andcommitted
Properly handle the case where src==dst in upcall_vec_append.
1 parent 36fb754 commit 8ad7f3b

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/rt/rust_upcall.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,12 @@ upcall_vec_append(rust_task *task, type_desc *t, type_desc *elem_t,
478478
size_t n_dst_bytes = skip_null ? dst->fill - 1 : dst->fill;
479479
rust_vec *new_vec = vec_grow(task, dst, n_src_bytes, &need_copy, t);
480480

481+
// If src and dst are the same (due to "v += v"), then dst getting
482+
// resized causes src to move as well.
483+
if (dst == src) {
484+
src = new_vec;
485+
}
486+
481487
if (need_copy) {
482488
// Copy any dst elements in, omitting null if doing str.
483489
copy_elements(task, elem_t, &new_vec->data, &dst->data, n_dst_bytes);

0 commit comments

Comments
 (0)