6 ms·
It is not only unknown if this holds on machines that don't use 2s complement, it is quite likely that this doesn't even hold on machines that do use 2s complem
by fhars 11y ago
It is not only unknown if this holds on machines that don't use 2s complement, it is quite likely that this doesn't even hold on machines that do use 2s complement, but have an optimizing compiler. In many cases, the overflow checks contains terms like
(b->slen+1) < 0
which an optimizing compiler could compile as
b->slen < -1
effectively switching the overflow test off (as there is no non-overflowing execution where this code will produce other behaviour than the original code, and behaviour on overflow is undefined, so the compiler can safely get rid of the addition).
- fhars 11y agoI just had to check what happens using a real compiler using realistic compiler options (gcc-4.9.2 -O2): https://github.com/websnarf/bstrlib/issues/8 https://github.com/websnarf/bstrlib/issues/8
- anon1385 11y agoThanks for doing that. It's much more productive than just moaning on HN like I did.