Skip to content

crash if vector is mutated while iterating #2015

Closed
@brson

Description

@brson
fn main() {                                                                                                                                                    
    let mut a = [0, 1, 2, 3];                                                                                                                                  
    let b = vec::filter(a) {|c|                                                                                                                                
        a = [];                                                                                                                                                
        true                                                                                                                                                   
    };                                                                                                                                                         
}  
==18087== Thread 8:
==18087== Invalid read of size 8
==18087==    at 0x4012C6: vec::filter1::_6a4a1114ba818cf3 (in /home/banderson/Dev/rust2/build/x86_64-unknown-linux-gnu/test/run-pass/test.stage1-x86_64-unknown-linux-gnu)
==18087==    by 0x400FBE: main::_843f8e32b1779b32 (in /home/banderson/Dev/rust2/build/x86_64-unknown-linux-gnu/test/run-pass/test.stage1-x86_64-unknown-linux-gnu)
==18087==    by 0x4010E9: _rust_main (in /home/banderson/Dev/rust2/build/x86_64-unknown-linux-gnu/test/run-pass/test.stage1-x86_64-unknown-linux-gnu)
==18087==    by 0x54C3E3A: task_start_wrapper(spawn_args*) (rust_task.cpp:176)
==18087==  Address 0x67ec620 is 16 bytes inside a block of size 48 free'd
==18087==    at 0x4C282ED: free (vg_replace_malloc.c:366)
==18087==    by 0x54D82B8: ??? (in /home/banderson/Dev/rust2/build/x86_64-unknown-linux-gnu/stage1/lib/rustc/x86_64-unknown-linux-gnu/lib/librustrt.so)
==18087== 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions