News for hackers. Stuff that matters.
Re:The Performance Cost of Integer Overflow Checking by pcwalton on Thursday December 18, 2014 @02:20AM (#8766346)
> Not to re-relitigate old discussion, but (as I'm sure you know) it's now more probable that you might overflow your integers and then pass them to unsafe code

Unsafe code needs to validate its inputs. That's part of the contract of unsafe code. If your unsafe code causes memory safety errors when given MAX_INT as an input, then your unsafe code is dangerously broken regardless of how easy it is for safe code to accidentally create a MAX_INT value.

Re:The Performance Cost of Integer Overflow Checking by SamReidHughes on Thursday December 18, 2014 @02:43AM (#8766380)
The relevant contract boundary isn't specifically at the edge of the unsafe block, it's at some other level like the public face of your ADT, inside which your unsafe and technically safe regions of code share the same set of invariants. It's immaterial whether the integer operation that results in overflow happens inside or outside what is technically the unsafe block, it should still be trapped. (Sorry about being unclear in that part of my previous comment.)
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.
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.