Re:Making Rust a Better Fit for Cheri and Other Platforms
by staticassertion on Thursday April 14, 2022 @01:32PM
(#31030265)
That seems easy to optimize out, especially given rust's mutability guarantees. If I have a u8 and I index into an array in a loop the compiler should be free to cast it to a usize above that loop, right?
The benefit being you can store much smaller structures, plus in the case of memory unsafety you reduce attacker control.
The vast majority of strings I personally use are certainly well under 2^32 bytes, and most are probably under 2^8.
The opposite is often the case, as the architecture may not support offsetting a pointer by those sizes, requiring lots of casting in tight loops. Making that explicit makes the programmer aware of this.
This is one major reason that C compiler developers want all overflow to be undefined behavior, as it allows them to upgrade for loops that use smaller index types to larger ones.