3 ms·
Does Rust do saturating arithmetic by default? If not, an integer overflow won't pass INT_MAX, it will pass some other int that might be a valid input to the u
by nitrogen 12y ago
Does Rust do saturating arithmetic by default? If not, an integer overflow won't pass INT_MAX, it will pass some other int that might be a valid input to the unsafe code.
- lmm 12y agoUnsafe code should not have memory safety errors when passed valid input. The point is that while integer overflow in Rust might cause incorrect program behaviour, it's not going to cause undefined behaviour (and therefore e.g. executing user input) the way it does in C.
- masklinn 12y agoRust does "computer" (silently overflowing) arithmetic by default. Saturating[0] and checked[1] are optionally available but require converting to methods (and some other changes for checked as it returns an Option) [0] http://doc.rust-lang.org/std/num/trait.Int.html#tymethod.saturating_add http://doc.rust-lang.org/std/num/trait.Int.html#tymethod.sat... [1] http://doc.rust-lang.org/std/num/trait.Int.html#tymethod.checked_add http://doc.rust-lang.org/std/num/trait.Int.html#tymethod.che...