Skip to content

A false negative caused by different loop forms #63

@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 4. However, when I replace the for item in iter (line 4) with for item in iter.skip(1) (line 5), the warning disappears.

use std::fmt::Debug;
fn func<I: Iterator<Item = impl Debug>>(iter: I) {
    let non_copy = Box::new(1234);
    for item in iter { // Reports a true Unsafe Dataflow warning
//  for item in iter.skip(1) { // Reports no warnings if we replace the loop statement
        unsafe { std::ptr::read(&non_copy); }
    }
}
pub fn main() {
    func(0..10);
}

Expected Behavior

Rudra should also report a warning when we usefor item in iter.skip(1) loop instead.

Actual Behavior

Rudra reports an unsafe dataflow warning when the loop for item in iter is used, but reports no warnings when the iter.skip(1) loop statement 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