Re:The Performance Cost of Integer Overflow Checking
by nitrogen on Thursday December 18, 2014 @02:28AM
(#8766361)
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.
[ Parent
| on HN ]
Re:The Performance Cost of Integer Overflow Checking
by masklinn on Thursday December 18, 2014 @08:03AM
(#8767046)
Rust 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.sat...
[1] http://doc.rust-lang.org/std/num/trait.Int.html#tymethod.che...
Re:The Performance Cost of Integer Overflow Checking
by lmm on Thursday December 18, 2014 @05:02AM
(#8766681)
Unsafe 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.