Skip to content

vec.rev_iter().collect() causes memory corruption #7558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
huonw opened this issue Jul 3, 2013 · 0 comments · Fixed by #7565
Closed

vec.rev_iter().collect() causes memory corruption #7558

huonw opened this issue Jul 3, 2013 · 0 comments · Fixed by #7565

Comments

@huonw
Copy link
Member

huonw commented Jul 3, 2013

fn main() {
    let v: &[int] = &[1i];
    let mut it = v.rev_iter();
    // println(fmt!("%?", (it.next(), it.next(), it.next(), it.next(), it.next(), )))
    let res = it.collect::<~[&int]>();
    // let mut res = ~[]; for it.advance |x| { res.push(x); }
    println(fmt!("%?", res));
}
$ ./rev-iter
*** Error in `./rev-iter': malloc(): memory corruption (fast): 0x00007f46cc201a70 ***
^C

(It hangs at lock_and_signal::wait (this=this@entry=0x610ed0) at /home/huon/rust/src/rt/sync/lock_and_signal.cpp:115.)

Either of the commented-out lines (after removing the .collect call) work fine so it doesn't appear to be caused by .rev_iter being entirely wrong. Significantly, the let mut res = ... line is actually essentially identical to what the .collect call is doing.

flip1995 pushed a commit to flip1995/rust that referenced this issue Aug 12, 2021
Rustup

r? `@ghost`

changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant