Skip to content

vec::consume/consume_mut are probably not failsafe. #3603

Closed
@brson

Description

@brson

Code looks like this:

fn consume<T>(+v: ~[T], f: fn(uint, +v: T)) unsafe {                                                                                                                          
    do as_imm_buf(v) |p, ln| {                                                                                                                                                
        for uint::range(0, ln) |i| {                                                                                                                                          
            let x <- *ptr::offset(p, i);                                                                                                                                      
            f(i, move x);                                                                                                                                                     
        }                                                                                                                                                                     
    }                                                                                                                                                                         

    raw::set_len(v, 0);                                                                                                                                                       
}         

What happens if the callback fails in the middle of the loop?

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions