Rudra
Rudra copied to clipboard
False negative in unsafe dataflow checker due to Copy trait
In the following code example, Rudra should have reported two unsafe dataflow warnings at lines 5 and 11. The false negative appears to be related to the trait bound, as removing the Copy trait in line 2 causes Rudra to successfully report both expected warnings.
use std::ptr;
fn insertion_sort_unsafe<T: Ord + Copy>(arr: &mut [T]) {
unsafe {
for i in 1..arr.len() {
let item = ptr::read(&arr[i]); // a false negative
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); // a false negative
}
}
}
pub fn main() {
let mut arr = [3, 2, 1];
insertion_sort_unsafe(&mut arr);
}