Skip to content

Commit 982f51a

Browse files
committed
stdlib: Fix reserve on zero-length interior vectors; uncomment test_unsafe_ptrs()
1 parent 391348e commit 982f51a

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/rt/rust_builtin.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ ivec_reserve(rust_task *task, type_desc *ty, rust_ivec *v, size_t n_elems)
587587
return; // Already big enough.
588588

589589
rust_ivec_heap *heap_part;
590-
if (v->fill) {
590+
if (v->fill || !v->payload.ptr) {
591591
// On stack; spill to heap.
592592
heap_part = (rust_ivec_heap *)task->malloc(new_alloc +
593593
sizeof(size_t));
@@ -625,6 +625,16 @@ ivec_to_ptr(rust_task *task, type_desc *ty, rust_ivec *v)
625625
return v->fill ? v->payload.data : v->payload.ptr->data;
626626
}
627627

628+
static size_t
629+
get_ivec_size(rust_ivec *v)
630+
{
631+
if (v->fill)
632+
return v->fill;
633+
if (v->payload.ptr)
634+
return v->payload.ptr->fill;
635+
return 0;
636+
}
637+
628638
/**
629639
* Copies elements in an unsafe buffer to the given interior vector. The
630640
* vector must have size zero.
@@ -633,7 +643,8 @@ extern "C" void
633643
ivec_copy_from_buf(rust_task *task, type_desc *ty, rust_ivec *v, void *ptr,
634644
size_t count)
635645
{
636-
if (v->fill || (v->payload.ptr && v->payload.ptr->fill)) {
646+
size_t old_size = get_ivec_size(v);
647+
if (old_size) {
637648
task->fail(1);
638649
return;
639650
}

src/test/run-pass/lib-ivec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn test_init_fn() {
4545

4646
fn main() {
4747
test_reserve_and_on_heap();
48-
//test_unsafe_ptrs();
48+
test_unsafe_ptrs();
4949
//test_init_fn();
5050
}
5151

0 commit comments

Comments
 (0)