Skip to content

Array::host, a safe method, can easily cause memory unsafety #135

Closed
@daboross

Description

@daboross

Correct me if I'm wrong, but it seems that

pub fn host<T>(&self, data: &mut [T]) {
checks neither T nor the length of the array to see if they are correct.

In Rust this should either be an unsafe method, or it should have runtime checks on the slice's length and type.

Using host::<String>() for example will give you a bunch of invalid strings - without using unsafe. Using said strings would violate memory safety, and likely cause programs to crash when the strings are deallocated.

I'm really interested in arrayfire in Rust, but it'd be even better if it adhered to Rust library principles. Methods which can violate safety with safe user input should be marked as unsafe to indicate this.

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