Amanieu / intrusive-rs

Intrusive collections for Rust
Apache License 2.0
412 stars 48 forks source link

segmentation fault from LinkedList #31

Closed nivkner closed 5 years ago

nivkner commented 5 years ago

the following code causes a segmentation fault when executed using git version of intrusive-collections

use intrusive_collections::{intrusive_adapter, LinkedListLink, LinkedList};

struct Value<T> {
    link: LinkedListLink,
    value: T, 
}

intrusive_adapter!(BoxedValueAdapter<T> = Box<Value<T>>: Value<T> { link: LinkedListLink });

fn main() {
    let mut list = LinkedList::new(BoxedValueAdapter::new());
    for x in 0..10 {
        let c = Value {
            link: LinkedListLink::new(),
            value: x, 
        };
        list.push_back(Box::new(c));
    }

    let mut curs = list.back_mut();
    for _ in 0..2 {
        curs.move_next();
    }

    let rest = curs.split_before();
    let mut curs = list.back_mut();
    curs.splice_after(rest);

    for x in &list {
        println!("{}", x.value);
    }
}

this is the output from running cargo miri with the same code

error[E0080]: Miri evaluation error: type validation failed: encountered 0, but expected something greater or equal to 1
   --> /home/user/.cargo/git/checkouts/intrusive-rs-9ecae677e4651113/e8a03c3/src/linked_list.rs:124:9
    |
124 |         (*self.0).next.set(next);
    |         ^^^^^^^^^^^^^^ Miri evaluation error: type validation failed: encountered 0, but expected something greater or equal to 1
    |
    = note: inside call to `intrusive_collections::linked_list::NodePtr::set_next` at /home/user/.cargo/git/checkouts/intrusive-rs-9ecae677e4651113/e8a03c3/src/linked_list.rs:186:9
    = note: inside call to `intrusive_collections::linked_list::NodePtr::splice` at /home/user/.cargo/git/checkouts/intrusive-rs-9ecae677e4651113/e8a03c3/src/linked_list.rs:504:21
note: inside call to `intrusive_collections::linked_list::CursorMut::<BoxedValueAdapter<i32>>::splice_after` at src/main.rs:27:5
   --> src/main.rs:27:5
    |
27  |     curs.splice_after(rest);
    |     ^^^^^^^^^^^^^^^^^^^^^^^

rustc version

rustc 1.35.0 (3c235d560 2019-05-20)
binary: rustc
commit-hash: 3c235d5600393dfe6c36eeed34042efad8d4f26e
commit-date: 2019-05-20
host: x86_64-unknown-linux-gnu
release: 1.35.0
LLVM version: 8.0
Amanieu commented 5 years ago

Fixed in 0.8.0.