3 ms·
Yes, people really do care about overflow. Because it gets used in security checks, and if they don't understand the behavior then their security checks don't
by btilly 7y ago
Yes, people really do care about overflow. Because it gets used in security checks, and if they don't understand the behavior then their security checks don't do what they expected.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=30475 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=30475 shows someone going hyperbolic over the issue. The technical arguments favor the GCC maintainers. However I prefer the position of the person going hyperbolic.
- JoeAltmaier 7y agoThat example was not 'overflow'. It was 'off by one'? That seems uninteresting, outside as you say the security issue where somebody might take advantage of it.
- btilly 7y agoThat example absolutely was overflow. The bug is, "assert(int+100 > int) optimized away". GCC has the behavior that overflowing a signed integer gives you a negative one. But an if tests that TESTS for that is optimized away! The reason is that overflow is undefined behavior, and therefore they are within their rights to do anything that they want. So they actually overflow in the fastest way possible, and optimize code on the assumption that overflow can't happen. The fact that almost no programmers have a mental model of the language that reconciles these two facts is an excellent reason to say that very few programmers should write in C. Because the compiler really is out to get you.
- JoeAltmaier 7y agoSure. Sorry, I was ambiguous. The earlier example of ++i in a loop I was thinking of. Anyway, yes, overflow for small ints is a real thing.