Spatial vs temporary safety
Spatial vs temporary safety
Posted Jan 22, 2025 19:21 UTC (Wed) by NYKevin (subscriber, #129325)In reply to: Spatial vs temporary safety by wahern
Parent article: A look at the recent rsync vulnerability
Perhaps your definition of "dynamically sized array" is different from mine. Personally, I call Vec a dynamically sized array.
Did you perhaps mean variable-length arrays? Because yes, Rust does expect you to use Vec or Box<[T]> for that use case instead of [T; N] arrays, and I suppose you could argue that that makes Rust deficient somehow, but I'm frankly not convinced. A heap allocation tied to an RAII type is arguably *more* convenient and ergonomic than alloca-with-better-syntax.
> In practice Rust does a better job with slices, but IIUC that just pushes the problem back to how you create the slice safely without resorting to unsafe{}. Both C and Rust would benefit from compiler improvements in this area.
Slices are fine if you construct the buffer in safe Rust. Virtually every type that can reasonably be used to construct a buffer in Rust can also be safely converted to &[T]. It's only a problem at the FFI layer when you have to use a buffer that is owned by foreign code, or where you're already using unsafe Rust to construct the buffer manually (for whatever reason).
