Skip to content

Possible unsound public API #1

@charlesxsh

Description

@charlesxsh
pub fn get_two_mut_elems<'a, T>(x: &'a mut Vec<T>, i: usize, j: usize) -> (&'a mut T, &'a mut T) {
    let len = x.len();
    assert!(i != j);
    assert!(i != len);
    assert!(j != len);
    let ptr = x.as_mut_ptr();
    unsafe { (ptr.add(i).as_mut().unwrap(), ptr.add(j).as_mut().unwrap()) }
}

The function is publicly accessible and two index are used in pointer.add but lack of efficient checks

Suggestions:

  1. adding appropriate checks
  2. make the function unsafe to notify the developer/user

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions