Skip to content

Unsafe Dataflow Detection Issue Related to Reference Handling​ #67

@RJerrica

Description

@RJerrica

Hi, Rudra fails to detect an unsafe data flow issue in the following program, which appears to be a false negative. This issue seems to be related to reference handling.

use std::ptr;
fn insertion_sort_unsafe<T: Ord>(arr: &mut [T]) {
    unsafe {
        for i in 1..arr.len() {
            let item = ptr::read(&arr[i]);
            let mut j = i - 1;
            while j >= 0 && &arr[j] > &item{
                j = j - 1;
            }
            ptr::copy(&mut arr[j + 1], &mut arr[j + 2], i - j - 1);
            ptr::write(&mut arr[j + 1], item);
        }
    }
}
pub fn main() {
    let mut arr = [3, 2, 1];
    insertion_sort_unsafe(&mut arr);
}

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