Skip to content

A false negative about Unsafe Dataflow detection in Rudra #62

Open
@stoneman258

Description

@stoneman258

Description

I find a false negative about the Unsafe Dataflow detection in Rudra. In the following code example, Rudra reports a warning at line 5, however, when I replace the ptr::read (line 5) with ptr::read_unaligned, the warning disappears.

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;
            while j > 0 && arr[j - 1] > item {
                ptr::swap(arr.as_mut_ptr().add(j), arr.as_mut_ptr().add(j - 1));
                j -= 1;
            }
            ptr::write_unaligned(arr.as_mut_ptr().add(j), item);
        }
    }
}
pub fn main() {
    let mut arr = [3, 2, 1];
    insertion_sort_unsafe(&mut arr);
}

Expected Behavior

Rudra should also report a warning when we use ptr::read_unaligned function instead.

Actual Behavior

Rudra reports no warnings when the ptr::read_unaligned is used instead.

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