Skip to content

Mark black_box function as unsafe #20

@kitcatier

Description

@kitcatier

Hello, I found a soundness issue in this crate.

bencher/lib.rs

Lines 590 to 596 in 8afeeb1

pub fn black_box<T>(dummy: T) -> T {
unsafe {
let ret = ptr::read_volatile(&dummy);
forget(dummy);
ret
}
}

https://doc.rust-lang.org/std/ptr/fn.read_volatile.html
The unsafe function called needs to ensure that the parameter must be :

  • src must be valid for reads.

  • src must be properly aligned.

  • src must point to a properly initialized value of type T.

and the developer who calls the black_box function may not notice this safety requirement.
Marking them unsafe also means that callers must make sure they know what they're doing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions