Idiom exclusion is really so important
Idiom exclusion is really so important
Posted Nov 13, 2024 10:37 UTC (Wed) by intelfx (subscriber, #130118)In reply to: Idiom exclusion is really so important by intelfx
Parent article: Progress on toolchain security features
Well, `if (a + b < a)` preserves the identity of participating arithmetic operations. When you see a `if (a + b < a)`, it is immediately obvious that you are dealing with a sum of `a` and `b`, and if you are familiar with wrapping arithmetic, it's also almost immediately parsable as checking for overflow.
On the other hand, `if (INT_MAX - a <= b)` does not preserve neither the identity of the operation, nor the identity of operands. You need significant brain time to mentally carry over the operands to one side, invert the signs and realize that we are talking about `a + b`, not some weird arithmetic expression with unrelated `a`, `b` and a constant.
Personally, it's a no-brainer which one is clearer.
