News for hackers. Stuff that matters.
Re:Understanding Integer Overflow in C/C++ (2012) [pdf] by nayuki on Saturday July 09, 2016 @04:05PM (#12063055)
> Asooka wrote:

  // i.e. you can always test if two positive values overflow with
  ((a + b) & 0x7F..F) > a
This is bad advice. The act of computing (a + b) is undefined behavior. Masking it afterward will not save you against a strict compiler that exploits (or traps) all undefined behaviors.
Re:Understanding Integer Overflow in C/C++ (2012) [pdf] by nkurz on Saturday July 09, 2016 @06:27PM (#12063634)
I think the 'Asooka' is aware of this, and was not offering advice. Rather, he was proposing that the world would be simpler if the specs were changed so that signed addition never resulted in undefined behavior. In this simpler counterfactual world, his test would work. In our current easier to optimize world, it would not.