GuillaumeGomez / rust-GSL

A GSL (the GNU Scientific Library) binding for Rust
190 stars 46 forks source link

Make safe the functions of the "fit" module #145

Closed Chris00 closed 5 months ago

Chris00 commented 5 months ago

The functions fit::linear,... were not checking that the length n was not too large (in which case the function would access memory outside the slice 😨). This PR fixes that.

P.S. IMHO, the strides and length parameters should be optional. For example a trait for “slice or (slice, stride)” would be simple and convenient (for strides, not the length n). For a better “Rust like” user experience, bigger changes are needed (I can try to propose something if you agree that such a change is beneficial).

GuillaumeGomez commented 5 months ago

Thanks for the added checks! Please fix the CI errors then I'll merge.

Chris00 commented 5 months ago

I fixed the cargo fmt part. The other error is unrelated to my changes — and would require a redesign of the cblas interface as, say, idamax returning an Index that no function accepts as argument makes idamax useless.

GuillaumeGomez commented 5 months ago

Indeed! New rust unused items analyzer is great. I'll send a fix for it. Thanks!