Skip to content

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

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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